Class TimeoutTerminationPolicy
- java.lang.Object
- org.springframework.batch.repeat.policy.CompletionPolicySupport
- org.springframework.batch.repeat.policy.TimeoutTerminationPolicy
- All Implemented Interfaces:
CompletionPolicy
public class TimeoutTerminationPolicy extends CompletionPolicySupport
Termination policy that times out after a fixed period. Allows graceful exit from a batch if the latest result comes in after the timeout expires (i.e. does not throw a timeout exception).
N.B. It may often be the case that the batch governed by this policy will be transactional, and the transaction might have its own timeout. In this case the transaction might throw a timeout exception on commit if its timeout threshold is lower than the termination policy.- Author:
- Dave Syer
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TimeoutTerminationPolicy.TimeoutBatchContext
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_TIMEOUT
Default timeout value in milliseconds (the value equivalent to 30 seconds).
Constructor Summary
Constructors Constructor Description TimeoutTerminationPolicy()
Default constructor.TimeoutTerminationPolicy(long timeout)
Construct aTimeoutTerminationPolicy
with the specified timeout value (in milliseconds).
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isComplete(RepeatContext context)
Check the timeout and complete gracefully if it has expires.RepeatContext
start(RepeatContext context)
Start the clock on the timeout.Methods inherited from class org.springframework.batch.repeat.policy.CompletionPolicySupport
isComplete, update
Field Detail
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUT
Default timeout value in milliseconds (the value equivalent to 30 seconds).- See Also:
- Constant Field Values
Constructor Detail
TimeoutTerminationPolicy
public TimeoutTerminationPolicy()
Default constructor.
TimeoutTerminationPolicy
public TimeoutTerminationPolicy(long timeout)
Construct aTimeoutTerminationPolicy
with the specified timeout value (in milliseconds).- Parameters:
timeout
- duration of the timeout.
Method Detail
isComplete
public boolean isComplete(RepeatContext context)
Check the timeout and complete gracefully if it has expires.- Specified by:
isComplete
in interfaceCompletionPolicy
- Overrides:
isComplete
in classCompletionPolicySupport
- Parameters:
context
- the current batch context.- Returns:
- true if the batch should terminate.
- See Also:
CompletionPolicy.isComplete(org.springframework.batch.repeat.RepeatContext)
start
public RepeatContext start(RepeatContext context)
Start the clock on the timeout.- Specified by:
start
in interfaceCompletionPolicy
- Overrides:
start
in classCompletionPolicySupport
- Parameters:
context
- the current context if one is already in progress.- Returns:
- a context object that can be used by the implementation to store internal state for a batch.
- See Also:
CompletionPolicy.start(RepeatContext)