Java Code Examples for java.util.concurrent.Executors.unconfigurableScheduledExecutorService()

The following are Jave code examples for showing how to use unconfigurableScheduledExecutorService() of the java.util.concurrent.Executors class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: ScheduledExecutorFactoryBean.java   View Source Code Vote up 6 votes
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	ScheduledExecutorService executor =
			createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);

	if (executor instanceof ScheduledThreadPoolExecutor && this.removeOnCancelPolicy != null) {
		((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(this.removeOnCancelPolicy);
	}

	// Register specified ScheduledExecutorTasks, if necessary.
	if (!ObjectUtils.isEmpty(this.scheduledExecutorTasks)) {
		registerTasks(this.scheduledExecutorTasks, executor);
	}

	// Wrap executor with an unconfigurable decorator.
	this.exposedExecutor = (this.exposeUnconfigurableExecutor ?
			Executors.unconfigurableScheduledExecutorService(executor) : executor);

	return executor;
}
 
Example 2
Project: openjdk-jdk10   File: ExecutorsTest.java   View Source Code Vote up 6 votes
/**
 * an unconfigurable newScheduledThreadPool successfully runs delayed task
 */
public void testUnconfigurableScheduledExecutorService() throws Exception {
    final ScheduledExecutorService p =
        Executors.unconfigurableScheduledExecutorService
        (Executors.newScheduledThreadPool(2));
    try (PoolCleaner cleaner = cleaner(p)) {
        final CountDownLatch proceed = new CountDownLatch(1);
        final Runnable task = new CheckedRunnable() {
            public void realRun() {
                await(proceed);
            }};
        long startTime = System.nanoTime();
        Future f = p.schedule(Executors.callable(task, Boolean.TRUE),
                              timeoutMillis(), MILLISECONDS);
        assertFalse(f.isDone());
        proceed.countDown();
        assertSame(Boolean.TRUE, f.get(LONG_DELAY_MS, MILLISECONDS));
        assertSame(Boolean.TRUE, f.get());
        assertTrue(f.isDone());
        assertFalse(f.isCancelled());
        assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
    }
}
 
Example 3
Project: guava-mock   File: MoreExecutors.java   View Source Code Vote up 5 votes
final ScheduledExecutorService getExitingScheduledExecutorService(
    ScheduledThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) {
  useDaemonThreadFactory(executor);
  ScheduledExecutorService service = Executors.unconfigurableScheduledExecutorService(executor);
  addDelayedShutdownHook(service, terminationTimeout, timeUnit);
  return service;
}
 
Example 4
Project: openjdk-jdk10   File: ExecutorsTest.java   View Source Code Vote up 5 votes
/**
 * unconfigurableScheduledExecutorService(null) throws NPE
 */
public void testUnconfigurableScheduledExecutorServiceNPE() {
    try {
        ExecutorService e = Executors.unconfigurableScheduledExecutorService(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 5
Project: googles-monorepo-demo   File: MoreExecutors.java   View Source Code Vote up 5 votes
final ScheduledExecutorService getExitingScheduledExecutorService(
    ScheduledThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) {
  useDaemonThreadFactory(executor);
  ScheduledExecutorService service = Executors.unconfigurableScheduledExecutorService(executor);
  addDelayedShutdownHook(service, terminationTimeout, timeUnit);
  return service;
}
 
Example 6
Project: hashsdn-controller   File: ScheduledThreadPoolWrapper.java   View Source Code Vote up 4 votes
@Override
public ScheduledExecutorService getExecutor() {
    return Executors.unconfigurableScheduledExecutorService(executor);
}