I am using core pool size of 3 and queue size of 50 and max pool size of 500.
Suppose core pool and queue has threads as following
core pool = [A, B, C]
queue = [D, E, F]
Will the thread D execute only after one of the treads in core pool finishes execution? or
Can a running thread say B in core pool go in waiting state and thread D gets pulled into core pool?
CodePudding user response:
One of A,B, or C tasks has to finish before the pool can start another task. Each task runs to completion or until canceled, going into a wait state doesn't free up the worker thread.
Here is the openjdk code for the ThreadPoolExecutor: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java. There is a runWorker method that gets the next task and calls run on it (line 1141).