Executors.newfixedthreadpool is meant to create a fixed-size thread pool, but what does this thread pool do?
1, when a task commits execution, it will first determine whether the number of thread pool has reached the upper limit, if not create a new thread to perform the task, even if the original created thread is idle and will not be used. See Source:
private boolean addifundercorepoolsize (Runnable firsttask) { Thread t = null; final ReentrantLock mainLock = this.mainLock; mainlock.lock (); try { if (poolsize < corepoolsize & & runstate == running) t = addthread (Firsttask); } finally { Mainlock.unlock (); } if (T == nuLL) return false; t.start (); return true ; }
A new thread is created as long as the thread pool is not full, and no new threads are created because other threads of the thread pool are idle
About Executors.newfixedthreadpool when to create a new thread