Sobes.tech
Senior

What will happen if corePoolSize=5, maxPoolSize=10, queue=100, and initially 5 tasks are added, then 7 more?

sobes.tech AI

Answer from AI

Given the parameters of ThreadPoolExecutor:

  • corePoolSize = 5
  • maxPoolSize = 10
  • queue (BlockingQueue) = 100

What happens when 5 tasks are added first, and then 7 more:

  1. The first 5 tasks will start immediately in 5 core threads, as the number of active threads is less than corePoolSize.
  2. The next 7 tasks (from 6th to 12th) will be placed in the queue, since corePoolSize has already been reached and the queue is not full.
  3. Since the queue is not full (can hold up to 100), new threads beyond corePoolSize are not created, even if maxPoolSize=10.

In summary:

  • 5 active core threads
  • 7 tasks in the queue
  • Threads from 6 to 10 (maxPoolSize) are not created, as the queue is not full.

Only when the queue is filled (more than 100 tasks), and core threads are busy, additional threads up to maxPoolSize will be created.

What will happen if corePoolSize=5, maxPoolSize=10… - sobes.tech