本文整理匯總了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;
}
}
}