Java Concurrency Interview

Executors and thread pools question 87 of 180 junior

Why name your threads, and how?

Thread names are the primary label in thread dumps, profilers, APM traces and log MDCs. When production is on fire and the dump shows 200 threads called pool-2-thread-N, you cannot tell which subsystem is stuck. payment-callback-7 answers the question instantly.

A ThreadFactory is also where you centralise the rest: daemon status, an UncaughtExceptionHandler that logs rather than prints, a context classloader, and a per-pool counter. Any small library or a handful of lines will do, and it costs nothing at runtime.

executors diagnostics

Quiz yourself on Executors and thread pools Suggest a correction