我有一个由scheduled timer task
管理的Spring container
。一旦kill it
抛出exception
RuntimeException
,我就无法找到Timer object
的方法。它一直在运行。有没有办法访问code
并从 <bean id="myTimer" class="com.aspect.MyTimer"></bean>
<bean id="timerTaskFactoryBean"
class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
<property name="targetObject" ref="myTimer"></property>
<property name="targetMethod" value="doSomething"></property>
</bean>
<bean id="timerTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="timerTask" ref="timerTaskFactoryBean"></property>
<property name="period" value="5000"></property>
</bean>
<bean class="org.springframework.scheduling.timer.TimerFactoryBean" id="timerBean">
<property name="scheduledTimerTasks">
<list>
<ref local="timerTask"></ref>
</list>
</property>
</bean>
取消它?
这是我的代码:
Java class
public class MyTimer {
public void doSomething(){
System.out.println("I am running...");
try{
throw new RuntimeException();
}
catch(RuntimeException e){
ScheduledTimerTask timer = (ScheduledTimerTask) App.appContext.getBeanFactory().getBean("timerTask");
timer.getTimerTask().cancel();
System.out.println("Timer cancelled due to..." +e);
}
}
{{1}}
}
答案 0 :(得分:0)
我猜你需要通过容器访问bean并取消它。