本文整理汇总了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();
}