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


Java ThreadPoolExecutor.DiscardOldestPolicy方法代碼示例

本文整理匯總了Java中java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadPoolExecutor.DiscardOldestPolicy方法的具體用法?Java ThreadPoolExecutor.DiscardOldestPolicy怎麽用?Java ThreadPoolExecutor.DiscardOldestPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.DiscardOldestPolicy方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSaturatedExecute_DiscardOldestPolicy

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * executor using DiscardOldestPolicy drops oldest task if saturated.
 */
public void testSaturatedExecute_DiscardOldestPolicy() {
    final CountDownLatch done = new CountDownLatch(1);
    LatchAwaiter r1 = awaiter(done);
    LatchAwaiter r2 = awaiter(done);
    LatchAwaiter r3 = awaiter(done);
    final ThreadPoolExecutor p =
        new CustomTPE(1, 1,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(1),
                      new ThreadPoolExecutor.DiscardOldestPolicy());
    try (PoolCleaner cleaner = cleaner(p, done)) {
        assertEquals(LatchAwaiter.NEW, r1.state);
        assertEquals(LatchAwaiter.NEW, r2.state);
        assertEquals(LatchAwaiter.NEW, r3.state);
        p.execute(r1);
        p.execute(r2);
        assertTrue(p.getQueue().contains(r2));
        p.execute(r3);
        assertFalse(p.getQueue().contains(r2));
        assertTrue(p.getQueue().contains(r3));
    }
    assertEquals(LatchAwaiter.DONE, r1.state);
    assertEquals(LatchAwaiter.NEW, r2.state);
    assertEquals(LatchAwaiter.DONE, r3.state);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:ThreadPoolExecutorSubclassTest.java

示例2: testDiscardOldestOnShutdown

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * execute using DiscardOldestPolicy drops task on shutdown
 */
public void testDiscardOldestOnShutdown() {
    final ThreadPoolExecutor p =
        new CustomTPE(1, 1,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(1),
                      new ThreadPoolExecutor.DiscardOldestPolicy());

    try { p.shutdown(); } catch (SecurityException ok) { return; }
    try (PoolCleaner cleaner = cleaner(p)) {
        TrackedNoOpRunnable r = new TrackedNoOpRunnable();
        p.execute(r);
        assertFalse(r.done);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:ThreadPoolExecutorSubclassTest.java

示例3: TransferModule

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private TransferModule(){
    mThreadPool = new ThreadPoolExecutor(10, 20, 3, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3),
            new ThreadPoolExecutor.DiscardOldestPolicy());
}
 
開發者ID:natjs,項目名稱:nat-network-transfer,代碼行數:5,代碼來源:TransferModule.java


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