本文整理了Java中java.util.TimerTask
类的一些代码示例,展示了TimerTask
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimerTask
类的具体详情如下:
包路径:java.util.TimerTask
类名称:TimerTask
[英]The TimerTask class represents a task to run at a specified time. The task may be run once or repeatedly.
[中]TimerTask类表示在指定时间运行的任务。任务可以运行一次或多次。
代码示例来源:origin: TooTallNate/Java-WebSocket
/**
* Cancel any running timer for the connection lost detection
* @since 1.3.4
*/
private void cancelConnectionLostTimer() {
if( connectionLostTimer != null ) {
connectionLostTimer.cancel();
connectionLostTimer = null;
}
if( connectionLostTimerTask != null ) {
connectionLostTimerTask.cancel();
connectionLostTimerTask = null;
}
}
代码示例来源:origin: apache/hbase
/**
* Trigger the timer immediately.
* <p>
* Exposed for testing.
*/
public void trigger() {
synchronized (timerTask) {
if (this.complete) {
LOG.warn("Timer already completed, not triggering.");
return;
}
LOG.debug("Triggering timer immediately!");
this.timer.cancel();
this.timerTask.run();
}
}
}
代码示例来源:origin: robovm/robovm
if (task.isScheduled()) {
throw new IllegalStateException("TimerTask is scheduled already");
代码示例来源:origin: apollographql/apollo-android
void schedule(final int taskId, final Runnable task, long delay) {
TimerTask timerTask = new TimerTask() {
@Override public void run() {
try {
task.run();
} finally {
cancelTask(taskId);
}
}
};
synchronized (this) {
TimerTask previousTimerTask = tasks.put(taskId, timerTask);
if (previousTimerTask != null) {
previousTimerTask.cancel();
}
if (timer == null) {
timer = new Timer("Subscription SmartTimer", true);
}
timer.schedule(timerTask, delay);
}
}
代码示例来源:origin: naver/ngrinder
reportTimerTask.run();
final Timer timer = new Timer(true);
timer.schedule(reportTimerTask, reportToConsoleInterval, reportToConsoleInterval);
m_terminalLogger.info("This test will shut down after {} ms", duration);
timer.schedule(shutdownTimerTask, duration);
reportTimerTask.cancel();
shutdownTimerTask.cancel();
reportTimerTask.run();
代码示例来源:origin: org.eclipse.jetty/jetty-util
public void schedule ()
{
if (_running)
{
if (_timer!=null)
_timer.cancel();
if (_task!=null)
_task.cancel();
if (getScanInterval() > 0)
{
_timer = newTimer();
_task = newTimerTask();
_timer.schedule(_task, 1010L*getScanInterval(),1010L*getScanInterval());
}
}
}
/**
代码示例来源:origin: k9mail/k-9
private void raiseNotification() {
if (timer != null) {
synchronized (timer) {
if (timerTask != null) {
timerTask.cancel();
timerTask = null;
}
timerTask = new TimerTask() {
@Override
public void run() {
if (startTime != null) {
Long endTime = SystemClock.elapsedRealtime();
Timber.i("TracingWakeLock for tag %s / id %d: has been active for %d ms, timeout = %d ms",
tag, id, endTime - startTime, timeout);
} else {
Timber.i("TracingWakeLock for tag %s / id %d: still active, timeout = %d ms",
tag, id, timeout);
}
}
};
timer.schedule(timerTask, 1000, 1000);
}
}
}
}
代码示例来源:origin: stackoverflow.com
final TimerTask tt = new TimerTask() {
@Override
public void run() {
if (count < 1000) {
//increment rectangles y position
//now repaint container so we can see changes in co-ordinates (unless you have a timer which repaints for you too)
count++;
} else {//counter is at 1000 stop the timer
cancel();
}
}
};
new Timer().scheduleAtFixedRate(tt, 0, 10);//start in 0milis and call run every 10 milis
代码示例来源:origin: net.sf.ehcache/ehcache
/**
* If the runtime environment restricts thread creation, the task is run
* inline for only one time. No further repeated execution happens for the
* task
*
* @see java.util.Timer#schedule(java.util.TimerTask, java.util.Date)
*/
public void schedule(TimerTask task, Date time) {
if (timerThreadRunning) {
timer.schedule(task, time);
} else {
task.run();
}
}
代码示例来源:origin: Demidong/ClockView
public void startCountDown(){
timer= new Timer();
TimerTask timerTask =new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(0);
}
};
timer.schedule(timerTask,0,1000);
timerTask.run();
}
public void finishCount(){
代码示例来源:origin: apache/storm
public void shutdown() {
if (cleanup != null) {
cleanup.cancel();
cleanup = null;
}
}
代码示例来源:origin: kingthy/TVRemoteIME
private void stopGetGuidTimer() {
if (this.mGetGuidTimer instanceof Timer) {
this.mGetGuidTimer.cancel();
this.mGetGuidTimer.purge();
this.mGetGuidTimer = null;
XLLog.i(TAG, "stopGetGuidTimer");
}
if (this.mGetGuidTimerTask instanceof TimerTask) {
this.mGetGuidTimerTask.cancel();
this.mGetGuidTimerTask = null;
}
}
代码示例来源:origin: apache/activemq
public static synchronized void cancel(Runnable task) {
TimerTask ticket = TIMER_TASKS.remove(task);
if (ticket != null) {
ticket.cancel();
CLOCK_DAEMON.purge();//remove cancelled TimerTasks
}
}
代码示例来源:origin: senseidb/zoie
public synchronized void setOptimizeDuration(long optimizeDuration) {
if (_optimizeDuration != optimizeDuration) {
_currentOptimizationTimerTask.cancel();
_optimizeTimer.purge();
_currentOptimizationTimerTask = new OptimizeTimerTask();
_optimizeTimer.scheduleAtFixedRate(_currentOptimizationTimerTask, _dateToStartOptimize,
optimizeDuration);
_optimizeDuration = optimizeDuration;
}
}
代码示例来源:origin: net.sf.ehcache/ehcache
/**
* If the runtime environment restricts thread creation, the task is run
* inline for only one time. No further repeated execution happens for the
* task
*
* @see java.util.Timer#scheduleAtFixedRate(java.util.TimerTask, java.util.Date, long)
*/
public void scheduleAtFixedRate(TimerTask task, Date firstTime, long period) {
if (timerThreadRunning) {
timer.scheduleAtFixedRate(task, firstTime, period);
} else {
task.run();
}
}
代码示例来源:origin: jphp-group/jphp
@Signature
public void run() {
getWrappedObject().run();
}
代码示例来源:origin: robovm/robovm
task.setScheduledTime(task.when);
task.run();
taskCompletedNormally = true;
} finally {
代码示例来源:origin: cSploit/android
@Override
public void onReceive(Context context, Intent intent) {
synchronized (getActivity()) {
if (mTask != null) {
mTask.cancel();
}
mTask = new TimerTask() {
@Override
public void run() {
check();
}
};
new Timer().schedule(mTask, CHECK_DELAY);
}
}
代码示例来源:origin: org.mortbay.jetty/jetty-util
public void schedule ()
{
if (_running)
{
if (_timer!=null)
_timer.cancel();
if (_task!=null)
_task.cancel();
if (getScanInterval() > 0)
{
_timer = newTimer();
_task = newTimerTask();
_timer.schedule(_task, 1000L*getScanInterval(),1000L*getScanInterval());
}
}
}
/**
代码示例来源:origin: internetarchive/heritrix3
checkpointTask.cancel();
this.timer.schedule(checkpointTask, periodMs, periodMs);
LOGGER.info("Installed Checkpoint TimerTask to checkpoint every " +
periodMs + " milliseconds.");
内容来源于网络,如有侵权,请联系作者删除!