类 TaskExecutorRepeatTemplate
- java.lang.Object
- org.springframework.batch.repeat.support.RepeatTemplate
- org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate
- 所有已实现的接口:
RepeatOperations
public class TaskExecutorRepeatTemplate extends RepeatTemplate
ProvidesRepeatOperations
support including interceptors that can be used to modify or monitor the behaviour at run time.
This implementation is sufficient to be used to configure transactional behaviour for each item by making theRepeatCallback
transactional, or for the whole batch by making the execute method transactional (but only then if the task executor is synchronous).
This class is thread-safe if its collaborators are thread-safe (interceptors, terminationPolicy, callback). Normally this will be the case, but clients need to be aware that if the task executor is asynchronous, then the other collaborators should be also. In particular theRepeatCallback
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).- 作者:
- Dave Syer
字段概要
字段 修饰符和类型 字段 说明 static int
DEFAULT_THROTTLE_LIMIT
Default limit for maximum number of concurrent unfinished results allowed by the template.从类继承的字段 org.springframework.batch.repeat.support.RepeatTemplate
logger
构造器概要
构造器 构造器 说明 TaskExecutorRepeatTemplate()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 thesetTaskExecutor(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.从类继承的方法 org.springframework.batch.repeat.support.RepeatTemplate
canContinue, executeAfterInterceptors, isComplete, isComplete, iterate, registerListener, setCompletionPolicy, setExceptionHandler, setListeners, start, update
字段详细资料
DEFAULT_THROTTLE_LIMIT
public static final int DEFAULT_THROTTLE_LIMIT
Default limit for maximum number of concurrent unfinished results allowed by the template.getNextResult(RepeatContext, RepeatCallback, RepeatInternalState)
.- 另请参阅:
- 常量字段值
构造器详细资料
TaskExecutorRepeatTemplate
public TaskExecutorRepeatTemplate()
方法详细资料
setThrottleLimit
public void setThrottleLimit(int throttleLimit)
Public setter for the throttle limit. The throttle limit is the largest number of concurrent tasks that can be executing at one time - if a new task arrives and the throttle limit is breached we wait for one of the executing tasks to finish before submitting the new one to theTaskExecutor
. Default value isDEFAULT_THROTTLE_LIMIT
. N.B. when used with a thread pooledTaskExecutor
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.
setTaskExecutor
public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
Setter for task executor to be used to run the individual item callbacks.- 参数:
taskExecutor
- a TaskExecutor- 抛出:
java.lang.IllegalArgumentException
- if the argument is null
getNextResult
protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state) throws java.lang.Throwable
Use thesetTaskExecutor(TaskExecutor)
to generate a result. The internal state in this case is a queue of unfinished result holders of typeResultHolder
. 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
在类中RepeatTemplate
- 参数:
context
- current BatchContext.callback
- the callback to execute.state
- maintained by the implementation.- 返回:
- a finished result.
- 抛出:
java.lang.Throwable
- any Throwable emitted during the iteration- 另请参阅:
RepeatTemplate.isComplete(RepeatContext)
,RepeatTemplate.createInternalState(RepeatContext)
waitForResults
protected boolean waitForResults(RepeatInternalState state)
Wait for all the results to appear on the queue and execute the after interceptors for each one.- 覆盖:
waitForResults
在类中RepeatTemplate
- 参数:
state
- the internal state.- 返回:
- true if
RepeatTemplate.canContinue(RepeatStatus)
is true for all results retrieved. - 另请参阅:
RepeatTemplate.waitForResults(org.springframework.batch.repeat.support.RepeatInternalState)
createInternalState
protected RepeatInternalState createInternalState(RepeatContext context)
从类复制的说明:RepeatTemplate
Create an internal state object that is used to store data needed internally in the scope of an iteration. Used by subclasses to manage the queueing and retrieval of asynchronous results. The default just provides an accumulation of Throwable instances for processing at the end of the batch.- 覆盖:
createInternalState
在类中RepeatTemplate
- 参数:
context
- the currentRepeatContext
- 返回:
- a
RepeatInternalState
instance. - 另请参阅:
RepeatTemplate.waitForResults(RepeatInternalState)