java - 使用 Executors.newCachedThreadPool() 时在线程池中创建的线程数

标签 java multithreading threadpool threadpoolexecutor

使用Executors.newCachedThreadPool()时,线程池中最初创建了多少个线程,Javadoc没有指定任何数字,是否有一个保证的数字,我们最初总是会得到10个之类的东西.以下文档:

newCachedThreadPool public static ExecutorService newCachedThreadPool() Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available. These pools will typically improve the performance of programs that execute many short-lived asynchronous tasks. Calls to execute will reuse previously constructed threads if available. If no existing thread is available, a new thread will be created and added to the pool. Threads that have not been used for sixty seconds are terminated and removed from the cache. Thus, a pool that remains idle for long enough will not consume any resources. Note that pools with similar properties but different details (for example, timeout parameters) may be created using ThreadPoolExecutor constructors. Returns: the newly created thread pool

最佳答案

答案是0

您可以在 source code 中找到就在 ThreadPoolExecutor creation 之后有no workers spawned

关于java - 使用 Executors.newCachedThreadPool() 时在线程池中创建的线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39028735/

相关文章:

java - 使用 OWL API 发出 SWRL 请求

c# - Windows上的多线程

c++ - QTimer对象是否在单独的线程中运行?其作用机理是什么?

scala - 没有单独线程的同步 Scala Future

java - IncompatibleClassChangeError : Class 'java.lang.VirtualMachineError' does not implement interface 'java.lang.CharSequence'

java - 如何从 ManagedBean 获取 xhtml jsf 页面上的 session 信息?

java - 在以下情况下建议使用 Thread.sleep()

java - 处理 api 中的线程数

生成对象的 Java 方法

c# - 在 AutoCAD .Net 插件中执行多线程作业