Java Code Examples for java.util.concurrent.Executors#unconfigurableExecutorService()

The following examples show how to use java.util.concurrent.Executors#unconfigurableExecutorService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadPoolExecutorFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
	ThreadPoolExecutor executor  = createExecutor(this.corePoolSize, this.maxPoolSize,
			this.keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
	if (this.allowCoreThreadTimeOut) {
		executor.allowCoreThreadTimeOut(true);
	}

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

	return executor;
}
 
Example 2
Source File: ThreadPoolExecutorFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
	ThreadPoolExecutor executor  = createExecutor(this.corePoolSize, this.maxPoolSize,
			this.keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
	if (this.allowCoreThreadTimeOut) {
		executor.allowCoreThreadTimeOut(true);
	}

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

	return executor;
}
 
Example 3
Source File: ThreadPoolExecutorFactoryBean.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
	ThreadPoolExecutor executor  = createExecutor(this.corePoolSize, this.maxPoolSize,
			this.keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
	if (this.allowCoreThreadTimeOut) {
		executor.allowCoreThreadTimeOut(true);
	}

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

	return executor;
}
 
Example 4
Source File: ThreadPoolExecutorFactoryBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
	ThreadPoolExecutor executor  = createExecutor(this.corePoolSize, this.maxPoolSize,
			this.keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
	if (this.allowCoreThreadTimeOut) {
		executor.allowCoreThreadTimeOut(true);
	}

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

	return executor;
}
 
Example 5
Source File: ExecutorsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * An unconfigurable newFixedThreadPool can execute runnables
 */
public void testUnconfigurableExecutorService() {
    final ExecutorService e = Executors.unconfigurableExecutorService(Executors.newFixedThreadPool(2));
    try (PoolCleaner cleaner = cleaner(e)) {
        e.execute(new NoOpRunnable());
        e.execute(new NoOpRunnable());
        e.execute(new NoOpRunnable());
    }
}
 
Example 6
Source File: ExecutorsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unconfigurableExecutorService(null) throws NPE
 */
public void testUnconfigurableExecutorServiceNPE() {
    try {
        ExecutorService e = Executors.unconfigurableExecutorService(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 7
Source File: MoreExecutors.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
final ExecutorService getExitingExecutorService(
    ThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) {
  useDaemonThreadFactory(executor);
  ExecutorService service = Executors.unconfigurableExecutorService(executor);
  addDelayedShutdownHook(service, terminationTimeout, timeUnit);
  return service;
}
 
Example 8
Source File: ExecutorsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * An unconfigurable newFixedThreadPool can execute runnables
 */
public void testUnconfigurableExecutorService() {
    final ExecutorService e = Executors.unconfigurableExecutorService(Executors.newFixedThreadPool(2));
    try (PoolCleaner cleaner = cleaner(e)) {
        e.execute(new NoOpRunnable());
        e.execute(new NoOpRunnable());
        e.execute(new NoOpRunnable());
    }
}
 
Example 9
Source File: ExecutorsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * unconfigurableExecutorService(null) throws NPE
 */
public void testUnconfigurableExecutorServiceNPE() {
    try {
        ExecutorService e = Executors.unconfigurableExecutorService(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 10
Source File: MoreExecutors.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
final ExecutorService getExitingExecutorService(ThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) {
        useDaemonThreadFactory(executor);
        ExecutorService service = Executors.unconfigurableExecutorService(executor);
        addDelayedShutdownHook(service, terminationTimeout, timeUnit);
        return service;
}
 
Example 11
Source File: MoreExecutors.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
final ExecutorService getExitingExecutorService(ThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) {
        useDaemonThreadFactory(executor);
        ExecutorService service = Executors.unconfigurableExecutorService(executor);
        addDelayedShutdownHook(service, terminationTimeout, timeUnit);
        return service;
}
 
Example 12
Source File: MoreExecutors.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
final ExecutorService getExitingExecutorService(ThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) {
        useDaemonThreadFactory(executor);
        ExecutorService service = Executors.unconfigurableExecutorService(executor);
        addDelayedShutdownHook(service, terminationTimeout, timeUnit);
        return service;
}
 
Example 13
Source File: MoreExecutors.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
final ExecutorService getExitingExecutorService(ThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) {
        useDaemonThreadFactory(executor);
        ExecutorService service = Executors.unconfigurableExecutorService(executor);
        addDelayedShutdownHook(service, terminationTimeout, timeUnit);
        return service;
}
 
Example 14
Source File: GameSyncExecutor.java    From asteria-3.0 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates and configures the update service for this game sync executor.
 * The returned executor is <b>unconfigurable</b> meaning it's configuration
 * can no longer be modified.
 * 
 * @param nThreads
 *            the amount of threads to create this service.
 * @return the newly created and configured service.
 */
private ExecutorService create(int nThreads) {
    if (nThreads <= 1)
        return null;
    ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(nThreads);
    executor.setRejectedExecutionHandler(new CallerRunsPolicy());
    executor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("GameSyncThread").build());
    return Executors.unconfigurableExecutorService(executor);
}