当RuntimeException发生时为什么java ThreadPoolExecutor会杀死线程?

时间:2015-04-17 06:03:21

标签: java multithreading threadpoolexecutor

它与Why java ThreadPoolExecutor kill thread when RuntimeException occurs?相同,但没有广泛可接受的答案。

在工人的跑步方法

/**
 * 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);
    }
}

为什么不简单地在while循环中捕获RuntimeException以让worker继续循环?

ps:我在Mac上使用Java 6。 Java 8做了一些改变,但与机制没有区别。

0 个答案:

没有答案