停止Spring集成框架中的任务
我想在给定事件后停止KeepAliverReceiver任务。我测试了以下解决方案,但没有一个有效:1)发送KeepAliverReceiver.stop()进行控制;2)实现生命周期并调用stop();3)停止调度程序。你知道如何在运行任务中停止任务吗停止Spring集成框架中的任务,spring,task,spring-integration,Spring,Task,Spring Integration,我想在给定事件后停止KeepAliverReceiver任务。我测试了以下解决方案,但没有一个有效:1)发送KeepAliverReceiver.stop()进行控制;2)实现生命周期并调用stop();3)停止调度程序。你知道如何在运行任务中停止任务吗 @MessageEndpoint public class KeepAliveReceiver implements Runnable, LifeCycle { private int limit; @Autowired private
@MessageEndpoint
public class KeepAliveReceiver implements Runnable, LifeCycle {
private int limit;
@Autowired
private ControlBusGateway controlGateway; // sending messages to control Channel
@Autowired
private ThreadPoolTaskScheduler myScheduler;
@Override
public void run() {
...
if ( event ) {
LOGGER.debug( "FAILOVER! Starting messageReceiveRouter. ");
controlGateway.send( new GenericMessage<String>( "@keepAliveReceiver.stop()" ) );
// not allowed
myScheduler.shutdown();
// not working, the scheduler keeps starting the keepAliveReceiver
this.stop();
//not working
}
}
@Override
public void stop() {
LOGGER.debug( "STOPPED!");
}
@MessageEndpoint
公共类KeepAliverReceiver实现可运行的生命周期{
私有整数限制;
@自动连线
专用ControlBusGateway;//向控制通道发送消息
@自动连线
私有线程池任务调度器myScheduler;
@凌驾
公开募捐{
...
如果(事件){
debug(“故障转移!启动messageReceiveRouter.”);
发送(新的GenericMessage(“@keepAliveReceiver.stop()”);
//不准
myScheduler.shutdown();
//如果不工作,计划程序将继续启动KeepAliverReceiver
这个。停止();
//不起作用
}
}
@凌驾
公共停车场(){
调试(“停止!”);
}
和计划程序的xml定义:
<task:scheduler id="myScheduler" pool-size="10" />
<task:scheduled-tasks>
<task:scheduled ref="keepAliveReceiver" method="run" fixed-rate="500" />
</task:scheduled-tasks>
,并将其更改为
您的问题是希望停止他自己的任务。从另一个角度来看,
只允许对SmartLifecycle
实施者进行操作。在进一步查看后,我已更改了答案。对不起