Example usage for java.util.concurrent ScheduledThreadPoolExecutor getRemoveOnCancelPolicy

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

Introduction

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

Prototype

public boolean getRemoveOnCancelPolicy() 

Source Link

Document

Gets the policy on whether cancelled tasks should be immediately removed from the work queue at time of cancellation.

Usage

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

public void testDefaultSchedulerThreadFactory() {
    DefaultScheduler defaultScheduler = new DefaultScheduler();
    try {/*from ww w .  j av  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();
    }
}