开发者

Stopping <task:scheduler> tasks

Our application runs both in client server mode and in standalone mode, when server code is embedded in the client process. In spring beans xml I have scheduled tasks, like

<task:scheduled-tasks scheduler="myScheduler">
        <task:scheduled ref="link-to-server" method="heartbeat" fixed-rate="1000"/>
</task:scheduled-tasks>

In the standalone mode the application is not exiting, because scheduler threads are not daemo开发者_如何转开发n threads. How can I stop them or make these threads daemon?

Thank you!


Don't make them daemon, that stops threads way too abrupt and therefor can leave your process in an inconsistent state. I believe a standard shutdown of the Spring context, and therefor the scheduler, simply interrupts all running threads. You should therefor poll Thread.currentThread().isInterrupted in your tasks to determine shutdown. Blocking methods like Object.wait() will throw InterruptedException upon interruption.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜