Do we need to shutdown ExecutorService fixedThreadPool

不羁的心 提交于 2019-12-05 15:35:32
Fabio Cardoso
  • newFixedThreadPool

public static ExecutorService newFixedThreadPool(int nThreads)

Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most nThreads threads will be active processing tasks. If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available. If any thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks. The threads in the pool will exist until it is explicitly shutdown.

Javadocs.

Here a good explanation.

FinalizableDelegatedExecutorService and ThreadPoolExecutor override finalize() to do the shutdown.

/**
* Invokes {@code shutdown} when this executor is no longer
* referenced and it has no threads.
*/
protected void finalize() {
    shutdown();
}

Acutally, I see no reason to explicitly shutdown the ExecutorService.

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