本文整理汇总了Java中java.util.concurrent.ScheduledThreadPoolExecutor.purge方法的典型用法代码示例。如果您正苦于以下问题:Java ScheduledThreadPoolExecutor.purge方法的具体用法?Java ScheduledThreadPoolExecutor.purge怎么用?Java ScheduledThreadPoolExecutor.purge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ScheduledThreadPoolExecutor
的用法示例。
在下文中一共展示了ScheduledThreadPoolExecutor.purge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: purgeExecutors
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
static void purgeExecutors() {
try {
Iterator<ScheduledThreadPoolExecutor> it = EXECUTORS.keySet().iterator();
while (it.hasNext()) {
ScheduledThreadPoolExecutor exec = (ScheduledThreadPoolExecutor) it.next();
if (exec.isShutdown()) {
it.remove();
} else {
exec.purge();
}
}
} catch (Throwable t) {
Exceptions.throwIfFatal(t);
RxJavaPlugins.getInstance().getErrorHandler().handleError(t);
}
}
示例2: testPurge
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
* purge eventually removes cancelled tasks from the queue
*/
public void testPurge() throws InterruptedException {
final ScheduledFuture[] tasks = new ScheduledFuture[5];
final Runnable releaser = new Runnable() { public void run() {
for (ScheduledFuture task : tasks)
if (task != null) task.cancel(true); }};
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
try (PoolCleaner cleaner = cleaner(p, releaser)) {
for (int i = 0; i < tasks.length; i++)
tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(),
LONG_DELAY_MS, MILLISECONDS);
int max = tasks.length;
if (tasks[4].cancel(true)) --max;
if (tasks[3].cancel(true)) --max;
// There must eventually be an interference-free point at
// which purge will not fail. (At worst, when queue is empty.)
long startTime = System.nanoTime();
do {
p.purge();
long count = p.getTaskCount();
if (count == max)
return;
} while (millisElapsedSince(startTime) < LONG_DELAY_MS);
fail("Purge failed to remove cancelled tasks");
}
}