Java Concurrency Interview

Executors and thread pools question 79 of 180 mid

Walk through what ThreadPoolExecutor does with a submitted task.

The order is the part people get backwards, and it explains most misconfigured pools:

  1. Fewer than corePoolSize threads: start a new thread, even if others are idle.
  2. Otherwise offer to the queue. If it accepts, done.
  3. Only if the queue refuses (a bounded queue that is full) start threads up to maximumPoolSize.
  4. If that fails too, hand the task to the RejectedExecutionHandler.

The consequence: with an unbounded queue, step 3 never happens, so maximumPoolSize is dead configuration and the pool never grows past core. People set a maximum of 200, watch the pool stay at 10, and conclude the setting is broken.

executors internals

Quiz yourself on Executors and thread pools Suggest a correction