I have a Spring Task defined on in spring app context xml:
<task:scheduler id="myScheduler" pool-size="1"/>
<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="MyClass" method="myMethod" fixed-delay="3000"/>
</task:scheduled-tasks>
So, how can I implement 开发者_StackOverflow社区to stop further execution of the tasks in case of an Exception, either in xml or in code by catching the Exception?
I don't think this is solvable using scheduled-tasks
, may be wrong of course.
There's an alternative though, config:
<task:annotation-driven scheduler="scheduler" />
<bean id="scheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="poolSize" value="5" />
<property name="errorHandler" ref="scheduledTaskErrorHandler" />
</bean>
<bean id="scheduledTaskErrorHandler" class="boo.ScheduledTaskErrorHandler" />
And the errorHandler:
public class ScheduledTaskErrorHandler implements ErrorHandler {
@Override
public void handleError(Throwable t) {
// do something, like shutdown the scheduler
}
}
精彩评论