Java Concurrency Interview

Executors and thread pools question 89 of 180 senior

What is work stealing, and which executors use it?

In a classic pool, all workers contend on one shared queue, and that queue is the bottleneck. In a work-stealing pool each worker owns a double-ended queue. It pushes and pops from its own end (LIFO, which keeps the freshest and most cache-warm task), and an idle worker steals from the opposite end (FIFO, taking the oldest and typically largest piece of work).

ForkJoinPool and the common pool behind parallel streams work this way. Executors.newWorkStealingPool and the virtual thread scheduler steal the same way but run their own queue FIFO (asyncMode), which suits event-style tasks that are never joined. It shines for recursive divide-and-conquer where tasks spawn subtasks; it buys little for uniform, independent, blocking tasks, where a plain pool is simpler and just as fast.

executors forkjoin

Quiz yourself on Executors and thread pools Suggest a correction