當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.getRemainingTimeInMillis方法代碼示例

本文整理匯總了Java中com.amazonaws.services.lambda.runtime.Context.getRemainingTimeInMillis方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getRemainingTimeInMillis方法的具體用法?Java Context.getRemainingTimeInMillis怎麽用?Java Context.getRemainingTimeInMillis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.lambda.runtime.Context的用法示例。


在下文中一共展示了Context.getRemainingTimeInMillis方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import com.amazonaws.services.lambda.runtime.Context; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 * @since 2017/12/20
 */
@Override
public void run()
{
	_LOGGER.debug("Started watchdog thread.");
	
	Context context = this.context;
	AtomicBoolean finished = this._finished;
	int windowtime = this.windowtime;
	
	for (;;)
	{
		// Sleep to pass the time by because otherwise CPU cycles will
		// just be burnt, but do not sleep for very small values because
		// most OSes
		int remaining = context.getRemainingTimeInMillis() - windowtime;
		if (remaining > _SLEEP_THRESHOLD)
		{
			try
			{
				Thread.sleep(remaining);
			}
		
			// Who dare interrupt my slumber?
			catch (InterruptedException e)
			{
				// Execution finished
				if (finished.get())
					return;
			}
			
			// Woke up from sleep, so the remaining time is completely
			// wrong now
			remaining = context.getRemainingTimeInMillis() - windowtime;
		}
		
		// Timed out
		if (remaining <= 0)
		{
			// A response from the main thread was server was generated
			// Whichever thread sets this variable first will be the one
			// to make the report
			if (this._generated.getAndSet(true))
				return;
			
			IOpipeConfiguration config = this.config;
			Thread sourcethread = this.sourcethread;
			
			_LOGGER.debug("Thread {} timed out.", sourcethread);
			
			// Generate a timeout exception, but for the ease of use in
			// debugging use the stack trace of the thread which timed out
			IOpipeTimeOutException reported = new IOpipeTimeOutException(
				"Execution timed out.");
			reported.setStackTrace(sourcethread.getStackTrace());
			
			// Send report to the service
			IOpipeMeasurement measurement = new IOpipeMeasurement(config,
				context);
			measurement.setThrown(reported);
			this.service.__sendRequest(measurement.buildRequest());
			
			// Do not need to execute anymore
			return;
		}
	}
}
 
開發者ID:iopipe,項目名稱:iopipe-java-core,代碼行數:71,代碼來源:__TimeOutWatchDog__.java


注:本文中的com.amazonaws.services.lambda.runtime.Context.getRemainingTimeInMillis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。