特定のイベントの後に 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>