当前位置: 首页>>代码示例>>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;未经允许,请勿转载。