0

特定のイベントの後に KeepAliveReceiver タスクを停止したいと思います。私は次の解決策をテストしましたが、どれも機能していません。実行中のタスク内からタスクを停止するにはどうすればよいですか?

@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>
4

1 に答える 1

1
  1. 空のコマンドを含むメッセージをcontrolGatewayに送信します ;-)

  2. あなたを「殺し」、<control-bus>それをに変更します

    <outbound-channel-adapter channel="stopSchedulerChannel" expression="@myScheduler.shutdown()">

  3. そして追加 <channel id="stopSchedulerChannel"> <dispatcher task-executor="executor"/> </channel>

  4. そして、適切なエグゼキュータBeanを構成します

あなたの問題は、自分から仕事を止めたいという願望についてです。反対側からは、実装者<control-bus>に対する操作のみが許可されますSmartLifecycle

于 2013-09-20T12:19:15.503 に答える