本文整理汇总了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);
}
示例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);
}
}
示例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());
}