1
votes

How many threads are initially created in the thread pool when using Executors.newCachedThreadPool() the Javadoc doesn't specify any number is there a guaranteed number that we will always get like 10 initially or something.Docs below:

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

1
If no existing thread is available, a new thread will be created and added to the pool.Sotirios Delimanolis
Im staying on creation of the pool how many threads are initially created 0, 1, 10, not guaranteed to be any integer? So if you think about Arraylist or something it initialized with 10 elements and if it needs to grow it will do so later.Marquis Blount

1 Answers

1
votes

The answer is 0.

You can find in source code that right after ThreadPoolExecutor creation there is no workers spawned.