本文整理匯總了Java中java.util.TimerTask.cancel方法的典型用法代碼示例。如果您正苦於以下問題:Java TimerTask.cancel方法的具體用法?Java TimerTask.cancel怎麽用?Java TimerTask.cancel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.TimerTask
的用法示例。
在下文中一共展示了TimerTask.cancel方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: close
import java.util.TimerTask; //導入方法依賴的package包/類
/**
* Close the ZooKeeper session and remove it
*/
synchronized public static void close(String contextPath, String session) {
String uri = concat(contextPath, session);
TimerTask t = zkSessionTimers.remove(uri);
if (t != null) {
t.cancel();
}
ZooKeeper zk = zkMap.remove(uri);
if (zk == null) {
return;
}
try {
zk.close();
} catch (InterruptedException e) {
LOG.error("Interrupted while closing ZooKeeper connection.", e);
}
}
示例2: stopTimer
import java.util.TimerTask; //導入方法依賴的package包/類
private void stopTimer(final String taskId) {
synchronized (mTimerTasks) {
TimerTask timer = mTimerTasks.remove(taskId);
if (timer != null) {
timer.cancel();
}
}
}
示例3: queryProgress
import java.util.TimerTask; //導入方法依賴的package包/類
private void queryProgress(TimerTask task) {
Cursor cursor = manager.query(query);
if (cursor.moveToFirst()) {
int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
int reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON));
Log.e("原因",String.valueOf(reason));
switch (status) {
case DownloadManager.STATUS_FAILED :
if (task != null)
task.cancel();
break;
case DownloadManager.STATUS_PAUSED :
if (task != null)
task.cancel();
//發廣播通知activity下載暫停了
Intent intent = new Intent();
intent.setAction("download has been paused");
sendBroadcast(intent);
break;
case DownloadManager.STATUS_RUNNING :
checkDownloadProgress(cursor);
break;
}
}
cursor.close();
}
示例4: cancelIfActive
import java.util.TimerTask; //導入方法依賴的package包/類
/**
* Cancels the specified task if it is active.
*/
private TimerTask cancelIfActive(TimerTask task) {
if (task != null) {
task.cancel();
}
return task;
}
示例5: scheduleTask
import java.util.TimerTask; //導入方法依賴的package包/類
public synchronized void scheduleTask(final String key, long millis, Runnable userTask) {
TimerTask refreshTask = tasksByKey.get(key);
if (refreshTask != null) {
refreshTask.cancel();
}
refreshTask = new MyDelayedTask(key, userTask);
tasksByKey.put(key, refreshTask);
timer.schedule(refreshTask, millis);
}
示例6: unScheduleGlobal
import java.util.TimerTask; //導入方法依賴的package包/類
public static void unScheduleGlobal(TimerTask listener) {
listener.cancel();
timer.purge();
}