我想在给定事件后停止KeepAliveReceiver任务。我测试了以下解决方案,没有一个工作1)发送keepAliveReceiver.stop()来控制,但是,2)实现生命周期并调用stop()3)停止调度程序。任何想法如何从正在运行的任务中停止任务?
@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!");
}
和调度程序的xml定义:
<task:scheduler id="myScheduler" pool-size="10" />
<task:scheduled-tasks>
<task:scheduled ref="keepAliveReceiver" method="run" fixed-rate="500" />
</task:scheduled-tasks>
答案 0 :(得分:1)
使用空命令发送至 controlGateway 消息; - )
'杀死'你的<control-bus>
并将其更改为
<outbound-channel-adapter channel="stopSchedulerChannel" expression="@myScheduler.shutdown()">
并添加
<channel id="stopSchedulerChannel">
<dispatcher task-executor="executor"/>
</channel>
你的问题是希望停止自己的任务。另一方<control-bus>
仅允许SmartLifecycle
实施者