Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.core.task
Class SimpleAsyncTaskExecutor

    java.lang.Object
      org.springframework.util.CustomizableThreadCreator
          org.springframework.core.task.SimpleAsyncTaskExecutor

All Implemented Interfaces:
  Serializable, AsyncTaskExecutor, TaskExecutor

    public class SimpleAsyncTaskExecutor

extends CustomizableThreadCreator
implements AsyncTaskExecutor, Serializable

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: This implementation does not reuse threads! Consider a thread-pooling TaskExecutor implementation instead, in particular for executing a large number of short-lived tasks.

Since:
  2.0
Author:
  Juergen Hoeller
See Also:
  `setConcurrencyLimit(int)`, `SyncTaskExecutor`, `TimerTaskExecutor`, `ThreadPoolTaskExecutor`, `WorkManagerTaskExecutor`, Serialized Form

Field Summary
`static String` | `DEFAULT_THREAD_NAME_PREFIX` Deprecated. as of Spring 2.0.3, since the default thread name prefix is now taken from the concrete class (could be a subclass)
`static int` | `NO_CONCURRENCY` Switch concurrency 'off': that is, don't allow any concurrent invocations.
`static int` | `UNBOUNDED_CONCURRENCY` Permit any number of concurrent invocations: that is, don't throttle concurrency.

Fields inherited from interface org.springframework.core.task.AsyncTaskExecutor
`TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE`

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 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).
`void` | `execute(Runnable task, long startTimeout)` Executes the given task, within a concurrency throttle if configured (through the superclass's settings).
`int` | `getConcurrencyLimit()` Return the maximum number of parallel accesses allowed.
`boolean` | `isThrottleActive()` Return whether this throttle is currently active.
`void` | `setConcurrencyLimit(int concurrencyLimit)` Set the maximum number of parallel accesses allowed

Methods inherited from class org.springframework.util.CustomizableThreadCreator
`createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadNamePrefix, setThreadPriority`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_THREAD_NAME_PREFIX

    public static final String DEFAULT_THREAD_NAME_PREFIX

  Deprecated. as of Spring 2.0.3, since the default thread name prefix is now taken from the concrete class (could be a subclass)
  Default thread name prefix: "SimpleAsyncTaskExecutor-".

### UNBOUNDED_CONCURRENCY

    public static final int UNBOUNDED_CONCURRENCY

  Permit any number of concurrent invocations: that is, don't throttle concurrency.

  See Also:
    Constant Field Values

### NO_CONCURRENCY

    public static final int NO_CONCURRENCY

  Switch concurrency 'off': that is, don't allow any concurrent invocations.

  See Also:
    Constant Field Values

Constructor Detail

### SimpleAsyncTaskExecutor

    public SimpleAsyncTaskExecutor()

  Create a new SimpleAsyncTaskExecutor with default thread name prefix.

### SimpleAsyncTaskExecutor

    public SimpleAsyncTaskExecutor(String threadNamePrefix)

  Create a new SimpleAsyncTaskExecutor with the given thread name prefix.

  Parameters:
    `threadNamePrefix` - the prefix to use for the names of newly created threads

Method Detail

### setConcurrencyLimit

    public void setConcurrencyLimit(int concurrencyLimit)

  Set the maximum number of parallel accesses allowed. -1 indicates no concurrency limit at all.

  In principle, this limit can be changed at runtime, although it is generally designed as a config time setting. NOTE: Do not switch between -1 and any concrete limit at runtime, as this will lead to inconsistent concurrency counts: A limit of -1 effectively turns off concurrency counting completely.

  See Also:
    `UNBOUNDED_CONCURRENCY`

### getConcurrencyLimit

    public int getConcurrencyLimit()

  Return the maximum number of parallel accesses allowed.

### isThrottleActive

    public boolean isThrottleActive()

  Return whether this throttle is currently active.

  Returns:
    `true` if the concurrency limit for this instance is active
  See Also:
    `getConcurrencyLimit()`, `setConcurrencyLimit(int)`

### execute

    public void execute(Runnable task)

  Executes the given task, within a concurrency throttle if configured (through the superclass's settings).

  Specified by:
    `execute` in interface `TaskExecutor`
  Parameters:
    `task` - the `Runnable` to execute (never `null`)
  See Also:
    `doExecute(Runnable)`

### execute

    public void execute(Runnable task,
                        long startTimeout)

  Executes the given task, within a concurrency throttle if configured (through the superclass's settings).

  Executes urgent tasks (with 'immediate' timeout) directly, bypassing the concurrency throttle (if active). All other tasks are subject to throttling.

  Specified by:
    `execute` in interface `AsyncTaskExecutor`
  Parameters:
    `task` - the `Runnable` to execute (never `null`)
    `startTimeout` - the time duration within which the task is supposed to start. This is intended as a hint to the executor, allowing for preferred handling of immediate tasks. Typical values are `AsyncTaskExecutor.TIMEOUT_IMMEDIATE` or `AsyncTaskExecutor.TIMEOUT_INDEFINITE` (the default as used by `TaskExecutor.execute(Runnable)`).
  See Also:
    `AsyncTaskExecutor.TIMEOUT_IMMEDIATE`, `doExecute(Runnable)`

### doExecute

    protected void doExecute(Runnable task)

  Template method for the actual execution of a task.

  The default implementation creates a new Thread and starts it.

  Parameters:
    `task` - the Runnable to execute
  See Also:
    `CustomizableThreadCreator.createThread(java.lang.Runnable)`, `Thread.start()`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2008 The Spring Framework.