Explain every parameter of ThreadPoolExecutor. When a task is submitted, what happens?
Executors.newFixedThreadPool hides traps (unbounded queue → OOM). Senior Java interviews want you to roll your own pool and justify each parameter.
Seven parameters: corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler.
Submit flow: (1) workers < core → create new worker; (2) core full → enqueue; (3) queue full → create new worker up to max; (4) max reached → rejection handler.
Queue choice matters: LinkedBlockingQueue (unbounded by default, skips step 3 forever — OOM risk), ArrayBlockingQueue (bounded), SynchronousQueue (no buffering, forces direct handoff).
Four built-in rejection policies: AbortPolicy (throw), CallerRunsPolicy (run on submitting thread — backpressure), DiscardPolicy (silently drop), DiscardOldestPolicy.
Sizing: CPU-bound ~ N_cpu + 1. I/O-bound ~ N_cpu × (1 + wait/compute). Always monitor queue depth and active count in prod.
I always create pools with new ThreadPoolExecutor, never Executors.newFixedThreadPool — that one uses an unbounded LinkedBlockingQueue which means maxPoolSize is dead code and memory grows until OOM. For a web server I typically go SynchronousQueue + large maxPoolSize + CallerRunsPolicy, so when we're overloaded submitters feel the backpressure instead of piling work. I set a named ThreadFactory so stack traces and logs show which pool a thread came from — huge for debugging. And I always wire up monitoring on getQueue().size() and getActiveCount() before prod.
Tomcat uses a custom TaskQueue that flips the order — prefer growing threads up to max before queueing.
Avoid Executors.newCachedThreadPool in uncontrolled environments — max is Integer.MAX_VALUE.
HireMe AI (即答侠) drills the "submit flow" with callbacks so you can recite the four branches without stumbling.
No by default. Set allowCoreThreadTimeOut(true) to let core threads die after keepAliveTime too.
Uncaught exceptions kill the worker; the pool replaces it. Always wrap tasks in try/catch or submit Futures and inspect Future.get().
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free