本文整理匯總了Java中java.util.concurrent.ScheduledThreadPoolExecutor.getTaskCount方法的典型用法代碼示例。如果您正苦於以下問題:Java ScheduledThreadPoolExecutor.getTaskCount方法的具體用法?Java ScheduledThreadPoolExecutor.getTaskCount怎麽用?Java ScheduledThreadPoolExecutor.getTaskCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.ScheduledThreadPoolExecutor
的用法示例。
在下文中一共展示了ScheduledThreadPoolExecutor.getTaskCount方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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");
}
}