Java 类java.util.concurrent.ThreadPoolExecutor.DiscardPolicy 实例源码

项目:openjdk-jdk10    文件:ThreadPoolExecutorTest.java   
/** Directly test simple ThreadPoolExecutor RejectedExecutionHandlers. */
public void testStandardRejectedExecutionHandlers() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 1, 1, SECONDS,
                               new ArrayBlockingQueue<Runnable>(1));
    final AtomicReference<Thread> thread = new AtomicReference<>();
    final Runnable r = new Runnable() { public void run() {
        thread.set(Thread.currentThread()); }};

    try {
        new AbortPolicy().rejectedExecution(r, p);
        shouldThrow();
    } catch (RejectedExecutionException success) {}
    assertNull(thread.get());

    new DiscardPolicy().rejectedExecution(r, p);
    assertNull(thread.get());

    new CallerRunsPolicy().rejectedExecution(r, p);
    assertSame(Thread.currentThread(), thread.get());

    // check that pool was not perturbed by handlers
    assertTrue(p.getRejectedExecutionHandler() instanceof AbortPolicy);
    assertEquals(0, p.getTaskCount());
    assertTrue(p.getQueue().isEmpty());
}
项目:components-ness-executors    文件:ThreadPoolConfiguration.java   
@Override
RejectedExecutionHandler getHandler() {
    return new ThreadPoolExecutor.DiscardPolicy();
}