Why does java ThreadPoolExecutor kill the thread when a RuntimeException is thrown?

This is the same as Why does java ThreadPoolExecutor kill the thread when a RuntimeException is thrown? but there is no broad acceptable answer.

In the "Workflow" method

/**
 * Main run loop
 */
public void run() {
    try {
        Runnable task = firstTask;
        firstTask = null;
        while (task != null || (task = getTask()) != null) {
            runTask(task);
            task = null;
        }
    } finally {
        workerDone(this);
    }
}

      

Why not just catch the RuntimeException in the while loop so that the worker continues the loop?

ps: I am using Java 6 on Mac. Java 8 makes some changes, but no different mechanism.

+3
java multithreading threadpoolexecutor


source to share


No one has answered this question yet

See similar questions:

3
Why does java ThreadPoolExecutor kill the thread when a RuntimeException is thrown?

or similar:

2936
When to use LinkedList over ArrayList in Java?
1989
"implements Runnable" vs "extends Thread" in Java
1338
Why does Java have transient fields?
1215
Why is Java code executed in comments with some Unicode characters?
761
What is daemon thread in Java?
696
Is there a way to kill the thread?
331
How do you kill Thread in Java?
223
How to disable a stream
1
Why ThreadPoolExecutor $ Worker extends AbstractQueuedSynchronizer
-3
ThreadPoolExecutor does not assign tasks to worker threads



All Articles
Loading...
X
Show
Funny
Dev
Pics