|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.util.ConcurrencyThrottleSupport org.springframework.core.task.SimpleAsyncTaskExecutor
public class SimpleAsyncTaskExecutor
TaskExecutor implementation that fires up a new Thread for each task, executing it asynchronously.
Supports limiting concurrent threads through the "concurrencyLimit" bean property. By default, the number of concurrent threads is unlimited.
NOTE: Does not reuse threads! Consider a thread-pooling TaskExecutor implementation instead, in particular for executing a large number of short-lived tasks.
ConcurrencyThrottleSupport.setConcurrencyLimit(int)
,
SyncTaskExecutor
,
TimerTaskExecutor
,
ThreadPoolTaskExecutor
,
WorkManagerTaskExecutor
,
Serialized FormField Summary | |
---|---|
static String |
DEFAULT_THREAD_NAME_PREFIX
Default thread name prefix: "SimpleAsyncTaskExecutor-". |
Fields inherited from class org.springframework.util.ConcurrencyThrottleSupport |
---|
logger, NO_CONCURRENCY, UNBOUNDED_CONCURRENCY |
Constructor Summary | |
---|---|
SimpleAsyncTaskExecutor()
Create a new SimpleAsyncTaskExecutor with default thread name prefix. |
|
SimpleAsyncTaskExecutor(String threadNamePrefix)
Create a new SimpleAsyncTaskExecutor with the given thread name prefix. |
Method Summary | |
---|---|
protected Thread |
createThread(Runnable task)
Template method for creation of a Thread. |
protected void |
doExecute(Runnable task)
Template method for the actual execution of a task. |
void |
execute(Runnable task)
Executes the given task, within a concurrency throttle if configured (through the superclass's settings). |
protected String |
getThreadNamePrefix()
Return the thread name prefix to use for the names of newly created threads. |
protected int |
getThreadPriority()
Return the priority of the threads that this executor creates. |
protected boolean |
isDaemon()
Return whether this executor should create daemon threads. |
protected String |
nextThreadName()
Return the thread name to use for a newly created thread. |
void |
setDaemon(boolean daemon)
Set whether this executor should create daemon threads, just executing as long as the application itself is running. |
void |
setThreadNamePrefix(String threadNamePrefix)
Specify the prefix to use for the names of newly created threads. |
void |
setThreadPriority(int threadPriority)
Set the priority of the threads that this executor creates. |
Methods inherited from class org.springframework.util.ConcurrencyThrottleSupport |
---|
afterAccess, beforeAccess, getConcurrencyLimit, isThrottleActive, setConcurrencyLimit |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_THREAD_NAME_PREFIX
Constructor Detail |
---|
public SimpleAsyncTaskExecutor()
public SimpleAsyncTaskExecutor(String threadNamePrefix)
threadNamePrefix
- the prefix to use for the names of newly created threadsMethod Detail |
---|
public void setThreadNamePrefix(String threadNamePrefix)
protected String getThreadNamePrefix()
public void setThreadPriority(int threadPriority)
Thread.NORM_PRIORITY
protected int getThreadPriority()
public void setDaemon(boolean daemon)
Default is "false": Tasks passed to this executor should be either short-lived or support explicit cancelling. Hence, if the application shuts down, tasks will by default finish their execution. Specify "true" for eager shutdown of threads that execute tasks.
Thread.setDaemon(boolean)
protected boolean isDaemon()
public final void execute(Runnable task)
execute
in interface TaskExecutor
task
- the Runnable
to execute (never null
)
NullPointerException
- if the supplied task is null
ConcurrencyThrottleSupport.beforeAccess()
,
doExecute(Runnable)
,
ConcurrencyThrottleSupport.afterAccess()
protected void doExecute(Runnable task)
Default implementation creates a new Thread and starts it.
task
- the Runnable to executecreateThread(java.lang.Runnable)
,
Thread.start()
protected Thread createThread(Runnable task)
Default implementation creates a new Thread for the given Runnable, applying an appropriate thread name.
task
- the Runnable to executenextThreadName()
protected String nextThreadName()
Default implementation returns the specified thread name prefix with an increasing thread count appended: for example, "SimpleAsyncTaskExecutor-0".
getThreadNamePrefix()
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |