本文整理了Java中java.util.TimerTask.scheduledExecutionTime()
方法的一些代码示例,展示了TimerTask.scheduledExecutionTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimerTask.scheduledExecutionTime()
方法的具体详情如下:
包路径:java.util.TimerTask
类名称:TimerTask
方法名:scheduledExecutionTime
[英]Returns the scheduled execution time. If the task execution is in progress it returns the execution time of the ongoing task. Tasks which have not yet run return an undefined value.
[中]返回计划的执行时间。如果任务正在执行,则返回正在执行的任务的执行时间。尚未运行的任务返回未定义的值。
代码示例来源:origin: jphp-group/jphp
@Signature
public long scheduledTime() {
return getWrappedObject().scheduledExecutionTime();
}
代码示例来源:origin: org.apache.servicemix/servicemix-common
public long scheduledExecutionTime() {
synchronized (lock) {
return timerTask == null ? 0 : timerTask.scheduledExecutionTime();
}
}
代码示例来源:origin: org.apache.servicemix/servicemix-core
public long scheduledExecutionTime() {
synchronized (lock) {
return timerTask == null ? 0 : timerTask.scheduledExecutionTime();
}
}
代码示例来源:origin: ioFog/Agent
@Override
public long scheduledExecutionTime() {
return super.scheduledExecutionTime();
}
代码示例来源:origin: ioFog/Agent
@Override
public long scheduledExecutionTime() {
return super.scheduledExecutionTime();
}
代码示例来源:origin: edu.emory.mathcs.util/emory-util-concurrent
/**
* Reschedule previously scheduled task unless it would postpone it.
* In other words, if the requested delay is longer than the time remaining
* until the previously scheduled execution, the request is ignored.
*
* @param delay the new delay before the task is to be executed,
* measured from the moment the method is invoked.
* @return true if successful, false otherwise (that is, if task is already
* running or complete)
*/
public synchronized void setAlarmDelayIfSooner(long delay) {
if (delay < 0) {
// infinite; can't be more restrictive than anything
return;
}
if (timerTask != null) {
long oldDelay = timerTask.scheduledExecutionTime() - System.currentTimeMillis();
if (delay >= oldDelay) {
// not more restrictive; ignore request
return;
}
}
setAlarmDelay(delay);
}
代码示例来源:origin: stackoverflow.com
public final class TimerTaskCatcher extends TimerTask {
private final TimerTask orig;
private final Thread.UncaughtExceptionHandler handler;
public TimerTaskCatcher(
TimerTask orig,
Thread.UncaughtExceptionHandler handler
} {
if (orig == null || handler == null) {
throw new NullPointerException();
}
this.orig = orig;
this.handler = handler;
}
@Override public boolean cancel() {
return orig.cancel();
}
@Override public void run() {
try {
orig.run();
} catch (Throwable exc) {
handler.uncaughtException(Thread.currentThread(), exc);
}
}
@Override public long scheduledExecutionTime() {
return orig.scheduledExecutionTime();
}
}
代码示例来源:origin: stackoverflow.com
public class Y {
public static void main(String[] args)throws Exception {
Timer timer = new Timer();
Action task = new Action();
timer.schedule( task, 2000, 1000 );
Thread.sleep( 4000 );
// this is where the user request a new interval, 2 sec.
task.cancel();
timer.schedule( new Action(), new Date(task.last + 2000), 2000 );
Thread.sleep( 8000 );
task.cancel();
}
}
class Action extends TimerTask {
private long last;
public void run(){
last = scheduledExecutionTime();
System.out.println( "tick" );
}
public long getLast(){
return last;
}
}
代码示例来源:origin: stackoverflow.com
@Override public void run() {
Date actualTime = new Date();
Date scheduledTime = new Date(this.scheduledExecutionTime());
wait_list.add(new Date[] { scheduledTime, actualTime });
if (actualTime.getTime() % 3 == 0) // Add two elements about 33% of the time
代码示例来源:origin: stackoverflow.com
long interval = minutes*60*1000;
long delay = interval;
if(prevTask != null){
delay = System.currentTimeMillis() - prevTask.scheduledExecutionTime(); //time left of previous setting
prevTask.cancel();
delay = interval - delay; //difference in time left & new interval
if(delay <=0) //if by new setting should've already ran, so run it ASAP...
delay = 2000;
logger.info(String.format("DB dump was already scheduled before. Set dump delay to %s minutes & setting new schedule to every %s minutes.", delay/60/1000, minutes));
}
TimerTask task = new TimerTask(){
private SimpleDateFormat ft = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss SSS");
private int minutes;
public TimerTask initialize(int minutes){
this.minutes = minutes;
return this;
}
public void run() {
try {
logger.info(String.format("Doing scheduled %s dump to DB. (Configured to occur every %s minutes.)", ft.format(new Date(this.scheduledExecutionTime())), minutes));
dumpToDB();
} catch (NamingException | SQLException e) {
e.printStackTrace();
}
}
}.initialize(minutes);
timer.schedule(task, delay, interval);
prevTask = task;
代码示例来源:origin: OPCFoundation/UA-Java-Legacy
/**
* Sets new Timer Task that timeouts pending requests.
* If task already exists but is too far in the future, it is canceled and new task assigned
*/
private void scheduleTimeoutRequestsTimer()
{
PendingRequest nextRequest = getNextTimeoutingPendingRequest();
// Cancel task
if (nextRequest == null) {
cancelTimeoutPendingRequestTask();
} else {
TimerTask task = timeoutPendingRequestsTask.get();
// Task does not exists or is not ok
if (task == null
|| task.scheduledExecutionTime() > nextRequest.timeoutTime) {
cancelTimeoutPendingRequestTask();
// Create a new task
task = TimerUtil.schedule(timer, timeoutRun, executor,
nextRequest.timeoutTime);
if (!timeoutPendingRequestsTask.compareAndSet(null, task))
// it was already set
task.cancel();
}
}
}
代码示例来源:origin: OPCFoundation/UA-Java-Legacy
/**
* Sets new Timer Task that timeouts pending requests.
* If task already exists but is too far in the future, it is canceled and new task assigned
*/
private void scheduleTimeoutRequestsTimer()
{
HttpsClientPendingRequest nextRequest = _getNextTimeoutingPendingRequest();
// Cancel task
if (nextRequest == null) {
cancelTimeoutPendingRequestTask();
} else {
TimerTask task = timeoutPendingRequestsTask.get();
// Task does not exists or is not ok
if (task == null || task.scheduledExecutionTime() > nextRequest.timeoutTime) {
cancelTimeoutPendingRequestTask();
// Create a new task
task = TimerUtil.schedule(timer, timeoutRun, executor,
nextRequest.timeoutTime);
if (!timeoutPendingRequestsTask.compareAndSet(null, task))
// it was already set
task.cancel();
}
}
}
代码示例来源:origin: stackoverflow.com
long timeLeft;
if (startTime < 0 || restart) {
startTime = scheduledExecutionTime();
timeLeft = totalTime;
restart = false;
} else {
timeLeft = totalTime - (scheduledExecutionTime() - startTime);
内容来源于网络,如有侵权,请联系作者删除!