Thread keeps running even after application has been stopped in Websphere

空扰寡人 提交于 2019-12-05 05:42:20

According to the CommonJ specs, a WorkManager will attempt to stop the execution of a Work only if its isDaemon() method returns true. Non daemon Works are expected to be short running so that they don't need to be stopped.

The problem is that by default, the isDaemon() method of the Work implementation used by Spring (and which actually wraps the Runnable) returns false. You can change that by making your Runnable implement SchedulingAwareRunnable.

However, that is not enough. If the WorkManager decides to stop the Work, then it will call Work#release() and it is the responsibility of the Work itself to make sure that it stops. In particular, the WorkManager will not attempt to interrupt the thread that is executing the Work (because that is not a reliable way to stop a thread). The problem is that the Work implementation used by Spring has an empty implementation for the release() method, so that you can't use that feature.

To summarize: if you want to use Spring, the only way to make sure that the execution is stopped is to design your own mechanism for that.

Note that it is still interesting to use SchedulingAwareRunnable, because this will avoid the warnings generated by WebSphere's thread monitor (about hanging threads).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!