If there are threads smaller than corePoolSize (core thread) executing, the current task will be submitted to the first place. Then the addWorker method will do some checks;
When a new task is put into the queue, it will be checked again (because the status will change or the thread pool is closed) to determine whether it needs to be rolled back or a new thread object needs to be created;
If the task cannot be put into the queue, it will try to add a new Thread object, otherwise the task will be rejected
PS: I remember reading a very good article that analyzed this method and the entire thread pool knowledge in detail. Let me help you find it...
update: In-depth understanding of Java thread pool
If there are threads smaller than corePoolSize (core thread) executing, the current task will be submitted to the first place. Then the addWorker method will do some checks;
When a new task is put into the queue, it will be checked again (because the status will change or the thread pool is closed) to determine whether it needs to be rolled back or a new thread object needs to be created;
If the task cannot be put into the queue, it will try to add a new Thread object, otherwise the task will be rejected
PS: I remember reading a very good article that analyzed this method and the entire thread pool knowledge in detail. Let me help you find it...
update: In-depth understanding of Java thread pool
Come on