Class RethrowOnThresholdExceptionHandler
- java.lang.Object
- org.springframework.batch.repeat.exception.RethrowOnThresholdExceptionHandler
- All Implemented Interfaces:
ExceptionHandler
public class RethrowOnThresholdExceptionHandler extends java.lang.Object implements ExceptionHandler
Implementation ofExceptionHandlerthat rethrows when exceptions of a given type reach a threshold. Requires anClassifierthat maps exception types to unique keys, and also a map from those keys to threshold values (Integer type).- Author:
- Dave Syer
Constructor Summary
Constructors Constructor Description RethrowOnThresholdExceptionHandler()Set up the exception handler.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidhandleException(RepeatContext context, java.lang.Throwable throwable)Classify the throwables and decide whether to re-throw based on the result.voidsetThresholds(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.Integer> thresholds)A map from exception classes to a threshold value of type Integer.voidsetUseParent(boolean useParent)Flag to indicate the the exception counters should be shared between sibling contexts in a nested batch.
Method Detail
setUseParent
public void setUseParent(boolean useParent)
Flag to indicate the the exception counters should be shared between sibling contexts in a nested batch. Default is false.- Parameters:
useParent- true if the parent context should be used to store the counters.
setThresholds
public void setThresholds(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.Integer> thresholds)
A map from exception classes to a threshold value of type Integer.- Parameters:
thresholds- the threshold value map.
handleException
public void handleException(RepeatContext context, java.lang.Throwable throwable) throws java.lang.Throwable
Classify the throwables and decide whether to re-throw based on the result. The context is used to accumulate the number of exceptions of the same type according to the classifier.- Specified by:
handleExceptionin interfaceExceptionHandler- Parameters:
context- the currentRepeatContext. Can be used to store state (via attributes), for example to count the number of occurrences of a particular exception type and implement a threshold policy.throwable- an exception.- Throws:
java.lang.Throwable- is thrown if number of exceptions exceeds threshold.- See Also:
ExceptionHandler.handleException(RepeatContext, Throwable)