Class TimeoutTerminationPolicy
java.lang.Object
org.springframework.batch.repeat.policy.CompletionPolicySupport
org.springframework.batch.repeat.policy.TimeoutTerminationPolicy
- All Implemented Interfaces:
CompletionPolicy
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.
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
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Default timeout value in milliseconds (the value equivalent to 30 seconds). -
Constructor Summary
ConstructorDescriptionDefault constructor.TimeoutTerminationPolicy
(long timeout) Construct aTimeoutTerminationPolicy
with the specified timeout value (in milliseconds). -
Method Summary
Modifier and TypeMethodDescriptionboolean
isComplete
(RepeatContext context) Check the timeout and complete gracefully if it has expires.start
(RepeatContext context) Start the clock on the timeout.Methods inherited from class org.springframework.batch.repeat.policy.CompletionPolicySupport
isComplete, update
-
Field Details
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUTDefault timeout value in milliseconds (the value equivalent to 30 seconds).- See Also:
-
-
Constructor Details
-
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 Details
-
isComplete
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:
-
start
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:
-