Example usage for java.util.concurrent ScheduledThreadPoolExecutor getExecuteExistingDelayedTasksAfterShutdownPolicy

List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor getExecuteExistingDelayedTasksAfterShutdownPolicy

Introduction

In this page you can find the example usage for java.util.concurrent ScheduledThreadPoolExecutor getExecuteExistingDelayedTasksAfterShutdownPolicy.

Prototype

public boolean getExecuteExistingDelayedTasksAfterShutdownPolicy() 

Source Link

Document

Gets the policy on whether to execute existing delayed tasks even when this executor has been shutdown .

Usage

From source file:org.elasticsearch.client.sniff.SnifferTests.java

public void testDefaultSchedulerThreadFactory() {
    DefaultScheduler defaultScheduler = new DefaultScheduler();
    try {/* w ww . j a v a 2 s. c o  m*/
        ScheduledExecutorService executorService = defaultScheduler.executor;
        assertThat(executorService, instanceOf(ScheduledThreadPoolExecutor.class));
        assertThat(executorService, instanceOf(ScheduledThreadPoolExecutor.class));
        ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) executorService;
        assertTrue(executor.getRemoveOnCancelPolicy());
        assertFalse(executor.getContinueExistingPeriodicTasksAfterShutdownPolicy());
        assertTrue(executor.getExecuteExistingDelayedTasksAfterShutdownPolicy());
        assertThat(executor.getThreadFactory(), instanceOf(Sniffer.SnifferThreadFactory.class));
        int iters = randomIntBetween(3, 10);
        for (int i = 1; i <= iters; i++) {
            Thread thread = executor.getThreadFactory().newThread(new Runnable() {
                @Override
                public void run() {

                }
            });
            assertThat(thread.getName(), equalTo("es_rest_client_sniffer[T#" + i + "]"));
            assertThat(thread.isDaemon(), is(true));
        }
    } finally {
        defaultScheduler.shutdown();
    }
}