Up-to-date coverage of task executor and scheduler variants
Includes a clarification of ThreadPoolExecutor configuration options and a note on early AsyncConfigurer initialization. Issue: SPR-16944 Issue: SPR-16945 (cherry picked from commitd58c09b) (cherry picked from commit5a11112)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,6 +76,11 @@ import org.springframework.core.Ordered;
|
||||
* method.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p><b>NOTE: {@link AsyncConfigurer} configuration classes get initialized early
|
||||
* in the application context bootstrap. If you need any dependencies on other beans
|
||||
* there, make sure to declare them 'lazy' as far as possible in order to let them
|
||||
* go through other post-processors as well.</b>
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
* @EnableAsync
|
||||
@@ -84,9 +89,9 @@ import org.springframework.core.Ordered;
|
||||
* @Override
|
||||
* public Executor getAsyncExecutor() {
|
||||
* ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
* executor.setCorePoolSize(7);
|
||||
* executor.setMaxPoolSize(42);
|
||||
* executor.setQueueCapacity(11);
|
||||
* executor.setCorePoolSize(5);
|
||||
* executor.setMaxPoolSize(10);
|
||||
* executor.setQueueCapacity(25);
|
||||
* executor.setThreadNamePrefix("MyExecutor-");
|
||||
* executor.initialize();
|
||||
* return executor;
|
||||
@@ -117,7 +122,7 @@ import org.springframework.core.Ordered;
|
||||
*
|
||||
* <task:annotation-driven executor="myExecutor" exception-handler="exceptionHandler"/>
|
||||
*
|
||||
* <task:executor id="myExecutor" pool-size="7-42" queue-capacity="11"/>
|
||||
* <task:executor id="myExecutor" pool-size="5-10" queue-capacity="25"/>
|
||||
*
|
||||
* <bean id="asyncBean" class="com.foo.MyAsyncBean"/>
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,6 +36,16 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
* "queueCapacity" properties) and exposing it as a bean reference of its native
|
||||
* {@link java.util.concurrent.ExecutorService} type.
|
||||
*
|
||||
* <p>The default configuration is a core pool size of 1, with unlimited max pool size
|
||||
* and unlimited queue capacity. This is roughly equivalent to
|
||||
* {@link java.util.concurrent.Executors#newSingleThreadExecutor()}, sharing a single
|
||||
* thread for all tasks. Setting {@link #setQueueCapacity "queueCapacity"} to 0 mimics
|
||||
* {@link java.util.concurrent.Executors#newCachedThreadPool()}, with immediate scaling
|
||||
* of threads in the pool to a potentially very high number. Consider also setting a
|
||||
* {@link #setMaxPoolSize "maxPoolSize"} at that point, as well as possibly a higher
|
||||
* {@link #setCorePoolSize "corePoolSize"} (see also the
|
||||
* {@link #setAllowCoreThreadTimeOut "allowCoreThreadTimeOut"} mode of scaling).
|
||||
*
|
||||
* <p>For an alternative, you may set up a {@link ThreadPoolExecutor} instance directly
|
||||
* using constructor injection, or use a factory method definition that points to the
|
||||
* {@link java.util.concurrent.Executors} class.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,11 +45,15 @@ import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
* providing several useful attributes: "corePoolSize", "maxPoolSize", "keepAliveSeconds"
|
||||
* (all supporting updates at runtime); "poolSize", "activeCount" (for introspection only).
|
||||
*
|
||||
* <p>For an alternative, you may set up a ThreadPoolExecutor instance directly using
|
||||
* constructor injection, or use a factory method definition that points to the
|
||||
* {@link java.util.concurrent.Executors} class. To expose such a raw Executor as a
|
||||
* Spring {@link org.springframework.core.task.TaskExecutor}, simply wrap it with a
|
||||
* {@link org.springframework.scheduling.concurrent.ConcurrentTaskExecutor} adapter.
|
||||
* <p>The default configuration is a core pool size of 1, with unlimited max pool size
|
||||
* and unlimited queue capacity. This is roughly equivalent to
|
||||
* {@link java.util.concurrent.Executors#newSingleThreadExecutor()}, sharing a single
|
||||
* thread for all tasks. Setting {@link #setQueueCapacity "queueCapacity"} to 0 mimics
|
||||
* {@link java.util.concurrent.Executors#newCachedThreadPool()}, with immediate scaling
|
||||
* of threads in the pool to a potentially very high number. Consider also setting a
|
||||
* {@link #setMaxPoolSize "maxPoolSize"} at that point, as well as possibly a higher
|
||||
* {@link #setCorePoolSize "corePoolSize"} (see also the
|
||||
* {@link #setAllowCoreThreadTimeOut "allowCoreThreadTimeOut"} mode of scaling).
|
||||
*
|
||||
* <p><b>NOTE:</b> This class implements Spring's
|
||||
* {@link org.springframework.core.task.TaskExecutor} interface as well as the
|
||||
@@ -58,13 +62,17 @@ import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
* exception handling follows the TaskExecutor contract rather than the Executor contract,
|
||||
* in particular regarding the {@link org.springframework.core.task.TaskRejectedException}.
|
||||
*
|
||||
* <p><b>If you prefer native {@link java.util.concurrent.ExecutorService} exposure instead,
|
||||
* consider {@link ThreadPoolExecutorFactoryBean} as an alternative to this class.</b>
|
||||
* <p>For an alternative, you may set up a ThreadPoolExecutor instance directly using
|
||||
* constructor injection, or use a factory method definition that points to the
|
||||
* {@link java.util.concurrent.Executors} class. To expose such a raw Executor as a
|
||||
* Spring {@link org.springframework.core.task.TaskExecutor}, simply wrap it with a
|
||||
* {@link org.springframework.scheduling.concurrent.ConcurrentTaskExecutor} adapter.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
* @see org.springframework.core.task.TaskExecutor
|
||||
* @see java.util.concurrent.ThreadPoolExecutor
|
||||
* @see ThreadPoolExecutorFactoryBean
|
||||
* @see ConcurrentTaskExecutor
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
Reference in New Issue
Block a user