gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:12:19 26 4
gpt4 key购买 nike

使用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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com