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 commit d58c09b)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -37,6 +37,16 @@ import org.springframework.lang.Nullable;
|
||||
* "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.
|
||||
|
||||
@@ -48,11 +48,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
|
||||
@@ -61,13 +65,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