Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
停止Spring集成框架中的任务_Spring_Task_Spring Integration - Fatal编程技术网

停止Spring集成框架中的任务

停止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

我想在给定事件后停止KeepAliverReceiver任务。我测试了以下解决方案,但没有一个有效:1)发送KeepAliverReceiver.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!");

}
@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
    实施者进行操作。在进一步查看后,我已更改了答案。对不起