本文整理汇总了Java中java.util.concurrent.RunnableScheduledFuture.isCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java RunnableScheduledFuture.isCancelled方法的具体用法?Java RunnableScheduledFuture.isCancelled怎么用?Java RunnableScheduledFuture.isCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.RunnableScheduledFuture
的用法示例。
在下文中一共展示了RunnableScheduledFuture.isCancelled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterExecute
import java.util.concurrent.RunnableScheduledFuture; //导入方法依赖的package包/类
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
if (r instanceof RunnableScheduledFuture) {
RunnableScheduledFuture<?> future = (RunnableScheduledFuture<?>) r;
Runnable task = mTasks.get(future);
if (future.isCancelled() || task == null) { // 当Runnable在run里面cancel自己时还会执行afterExecute方法;
if (LogUtils.isDebug()) {
LogUtils.d(TAG, "afterExecute.isCancelled.futrue = " + r + ", throwable = " + t);
}
} else {
int futureHashCode = future.hashCode();
if (LogUtils.isDebug() && mDebugTimes != null) { // LogUtils.isDebug()是动态设置的,有可能在beforeExecute里为false,在afterExecute里为true了;
LogUtils.d(TAG, "afterExecute.task = " + task
+ ", time = " + (SystemClock.elapsedRealtime() - mDebugTimes.get(futureHashCode))
+ ", throwable = " + t
+ ", sBackgroundExecutor = " + this);
if (!future.isPeriodic()) {
mDebugTimes.remove(futureHashCode);
}
}
if (!future.isPeriodic()) {
mRunningTasks.remove(task.hashCode());
mTasks.remove(future);
}
}
}
checkAndThrowThreadPoolExecutorThrowable(TAG + ".afterExecute", r, t);
}
示例2: isAllTasksCancelled
import java.util.concurrent.RunnableScheduledFuture; //导入方法依赖的package包/类
boolean isAllTasksCancelled() {
for(RunnableScheduledFuture<?> task: tasks) {
if (!task.isCancelled()) {
return false;
}
}
return true;
}