public class TaskExecutorRepeatTemplate extends RepeatTemplate
RepeatOperations
support including interceptors that can be
used to modify or monitor the behaviour at run time.RepeatCallback
transactional,
or for the whole batch by making the execute method transactional (but only
then if the task executor is synchronous).RepeatCallback
that
is wrapped in the execute method must be thread-safe - often it is based on
some form of data source, which itself should be both thread-safe and
transactional (multiple threads could be accessing it at any given time, and
each thread would have its own transaction).Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_THROTTLE_LIMIT
Default limit for maximum number of concurrent unfinished results allowed
by the template.
|
logger
Constructor and Description |
---|
TaskExecutorRepeatTemplate() |
Modifier and Type | Method and Description |
---|---|
protected RepeatInternalState |
createInternalState(RepeatContext context)
Create an internal state object that is used to store data needed
internally in the scope of an iteration.
|
protected RepeatStatus |
getNextResult(RepeatContext context,
RepeatCallback callback,
RepeatInternalState state)
Use the
setTaskExecutor(TaskExecutor) to generate a result. |
void |
setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
Setter for task executor to be used to run the individual item callbacks.
|
void |
setThrottleLimit(int throttleLimit)
Public setter for the throttle limit.
|
protected boolean |
waitForResults(RepeatInternalState state)
Wait for all the results to appear on the queue and execute the after
interceptors for each one.
|
canContinue, executeAfterInterceptors, isComplete, isComplete, iterate, registerListener, setCompletionPolicy, setExceptionHandler, setListeners, start, update
public static final int DEFAULT_THROTTLE_LIMIT
getNextResult(RepeatContext, RepeatCallback, RepeatInternalState)
.public void setThrottleLimit(int throttleLimit)
TaskExecutor
. Default value is DEFAULT_THROTTLE_LIMIT
.
N.B. when used with a thread pooled TaskExecutor
the thread pool
might prevent the throttle limit actually being reached (so make the core
pool size larger than the throttle limit if possible).throttleLimit
- the throttleLimit to set.public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
taskExecutor
- a TaskExecutorjava.lang.IllegalArgumentException
- if the argument is nullprotected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state) throws java.lang.Throwable
setTaskExecutor(TaskExecutor)
to generate a result. The
internal state in this case is a queue of unfinished result holders of
type ResultHolder
. The holder with the return value should not be
on the queue when this method exits. The queue is scoped in the calling
method so there is no need to synchronize access.getNextResult
in class RepeatTemplate
context
- current BatchContext.callback
- the callback to execute.state
- maintained by the implementation.java.lang.Throwable
RepeatTemplate.isComplete(RepeatContext)
,
RepeatTemplate.createInternalState(RepeatContext)
protected boolean waitForResults(RepeatInternalState state)
waitForResults
in class RepeatTemplate
state
- the internal state.RepeatTemplate.canContinue(RepeatStatus)
is true for all
results retrieved.RepeatTemplate.waitForResults(org.springframework.batch.repeat.support.RepeatInternalState)
protected RepeatInternalState createInternalState(RepeatContext context)
RepeatTemplate
createInternalState
in class RepeatTemplate
context
- the current RepeatContext
RepeatInternalState
instance.RepeatTemplate.waitForResults(RepeatInternalState)