且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java Servlet中的ExecutorService

更新时间:2023-12-03 22:44:04

第一个不应该是一个选项。线程池(和可能的任何池)的想法是最小化构建池成员(在这种情况下,工作线程)所需的开销和内存。因此,一般来说,当您的应用程序启动时,应启动池,并在关闭时销毁。

The first should not be an option. The idea of a thread pool (and probably any pool) is to minimize the overhead and memory required for the construction of the pool members (in this case, the worker threads). so In general the pools should be inited when your application is started and destroyed when it shuts down.

至于2和3之间的选择,请检查接受的答案下面的帖子。答案解释了差异,然后您可以决定哪一种更适合您的需求: newcachedthreadpool-vs-newfixedthreadpool

As for the choice between 2 and 3, please check the accepted answer in the following post. The answer explains the difference and you can then decide which one suits your needs better : newcachedthreadpool-v-s-newfixedthreadpool