當前位置: 首頁>>代碼示例>>Java>>正文


Java ScheduledThreadPoolExecutor.purge方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:NewThreadWorker.java

示例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");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:ScheduledExecutorTest.java


注:本文中的java.util.concurrent.ScheduledThreadPoolExecutor.purge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。