From javadoc for ThreadPoolExecutor
:
When a new task is submitted in method execute(java.lang.Runnable) .... If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full.
How can I make ThreadPool
that will start new thread instead of submitting task to queue in this situation?
Example:
I have thread with corePoolSize=5 and maxPoolSize=10 and unbounded queue.
Suppose corePoolSize threads is busy right now, and new task is arrived - pool must start new thread and execute new task.
Suppose maxPoolSize threads is busy right now, and new task is arrived - pool must persist task into queue, and first free thread must take this task and execute.