开发者

java - what happens to runnables that hang in threadpoolexecutor?

If a runnable hangs while running in a threadpoolexecutor, is there a way to find out that it has hung and kill the runnable? Will the getActiveCount method consider a runnable that's hanging as "a开发者_开发知识库ctively executing"?


There is no safe way to kill a thread which is busy (other than running it in another process and killing it) You can detect if a thread is taking to long by waiting for the result with a timeout. You can also add a task to cancel the task after a timeout, however this will only interrupt a thread's task, not kill it.

You are better off determining why the task "hangs" and fixing the code so it doesn't.

When you start a task you store Thread.currentThread() is a share variable. You can then take a getStackTrace() periodically to determine what it is doing and log it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜