org.springframework.batch.admin.util
Class ThrottledTaskExecutor

java.lang.Object
  extended by org.springframework.batch.admin.util.ThrottledTaskExecutor
All Implemented Interfaces:
Executor, TaskExecutor

public class ThrottledTaskExecutor
extends Object
implements 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.

Author:
Dave Syer

Constructor Summary
ThrottledTaskExecutor()
          Create a ThrottledTaskExecutor with infinite (Integer.MAX_VALUE) throttle limit.
ThrottledTaskExecutor(TaskExecutor taskExecutor)
          Create a ThrottledTaskExecutor with infinite (Integer.MAX_VALUE) throttle limit.
ThrottledTaskExecutor(TaskExecutor taskExecutor, int throttleLimit)
          Create a ThrottledTaskExecutor with finite throttle limit.
 
Method Summary
 void execute(Runnable task)
          Submit a task for execution by the delegate task executor, blocking if the throttleLimit is exceeded.
 void setTaskExecutor(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThrottledTaskExecutor

public ThrottledTaskExecutor()
Create a ThrottledTaskExecutor with infinite (Integer.MAX_VALUE) throttle limit. A task can always be submitted.


ThrottledTaskExecutor

public ThrottledTaskExecutor(TaskExecutor taskExecutor)
Create a ThrottledTaskExecutor with infinite (Integer.MAX_VALUE) throttle limit. A task can always be submitted.

Parameters:
taskExecutor - the TaskExecutor to use

ThrottledTaskExecutor

public ThrottledTaskExecutor(TaskExecutor taskExecutor,
                             int throttleLimit)
Create a ThrottledTaskExecutor with finite throttle limit. The submit method will block when this limit is reached until one of the tasks has finished.

Parameters:
taskExecutor - the TaskExecutor to use
throttleLimit - the throttle limit
Method Detail

setThrottleLimit

public void setThrottleLimit(int throttleLimit)
Limits the number of concurrent executions on the enclosed task executor. Do not call this after initialization (for configuration purposes only).

Parameters:
throttleLimit - the throttle limit to apply

setTaskExecutor

public void setTaskExecutor(TaskExecutor taskExecutor)
Public setter for the 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.

Parameters:
taskExecutor -

execute

public void execute(Runnable task)
Submit a task for execution by the delegate task executor, blocking if the throttleLimit is exceeded.

Specified by:
execute in interface Executor
Specified by:
execute in interface TaskExecutor
See Also:
TaskExecutor.execute(Runnable)

size

public int size()
Get an estimate of the number of pending requests.

Returns:
the estimate


Copyright © 2011. All Rights Reserved.