Example usage for java.util.concurrent ScheduledThreadPoolExecutor getContinueExistingPeriodicTasksAfterShutdownPolicy

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

Introduction

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

Prototype

public boolean getContinueExistingPeriodicTasksAfterShutdownPolicy() 

Source Link

Document

Gets the policy on whether to continue executing existing periodic 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 {/*from  w  w w .jav  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();
    }
}