public class ThrottledTaskExecutor extends Object implements org.springframework.core.task.TaskExecutor
A TaskExecutor
with a throttle limit which works by delegating to an
existing task executor and limiting the number of tasks submitted.
A throttle limit is provided to limit the number of pending requests over and
above the features provided by the other task executors. The submit method
blocks until there are results available to retrieve. This limit is different
(and orthogonal) to any queue size imposed by the delegate
TaskExecutor
: such queues normally do not throttle, in the sense that
they always accept more work, until they fill up, at which point they reject.
The point of a throttle is to not reject any work, but to still limit the
number of concurrent tasks.
Constructor and Description |
---|
ThrottledTaskExecutor()
Create a
ThrottledTaskExecutor with infinite
(Integer.MAX_VALUE) throttle limit. |
ThrottledTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
Create a
ThrottledTaskExecutor with infinite
(Integer.MAX_VALUE) throttle limit. |
ThrottledTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor,
int throttleLimit)
Create a
ThrottledTaskExecutor with finite throttle
limit. |
Modifier and Type | Method and Description |
---|---|
void |
execute(Runnable task)
Submit a task for execution by the delegate task executor, blocking if
the throttleLimit is exceeded.
|
void |
setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
Public setter for the
TaskExecutor to be used to execute the
tasks submitted. |
void |
setThrottleLimit(int throttleLimit)
Limits the number of concurrent executions on the enclosed task executor.
|
int |
size()
Get an estimate of the number of pending requests.
|
public ThrottledTaskExecutor()
ThrottledTaskExecutor
with infinite
(Integer.MAX_VALUE) throttle limit. A task can always be submitted.public ThrottledTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
ThrottledTaskExecutor
with infinite
(Integer.MAX_VALUE) throttle limit. A task can always be submitted.taskExecutor
- the TaskExecutor
to usepublic ThrottledTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor, int throttleLimit)
ThrottledTaskExecutor
with finite throttle
limit. The submit method will block when this limit is reached until one
of the tasks has finished.taskExecutor
- the TaskExecutor
to usethrottleLimit
- the throttle limitpublic void setThrottleLimit(int throttleLimit)
throttleLimit
- the throttle limit to applypublic void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
TaskExecutor
to be used to execute the
tasks submitted. The default is synchronous, executing tasks on the
calling thread. In this case the throttle limit is irrelevant as there
will always be at most one task pending.taskExecutor
- TaskExecutor
public void execute(Runnable task)
public int size()
Copyright © 2015. All rights reserved.