Java / Java Concurrency and Multi Threading in Java 17 and Java 21 Interview questions
What is the difference between ExecutorService shutdown() and shutdownNow()?
| shutdown() | shutdownNow() |
| Graceful: stops accepting new tasks but lets queued and running tasks finish. | Aggressive: attempts to stop actively executing tasks and returns tasks that were never started. |
| Does not interrupt running tasks. | Interrupts running tasks via Thread.interrupt(). |
| Returns void. | Returns a List<Runnable> of tasks that were awaiting execution. |
Neither call blocks; both return immediately after signaling the pool. To actually wait for termination, you follow up with awaitTermination(timeout, unit), checking its boolean result to know whether the pool finished in time.
A common pattern is to call shutdown() first for a graceful stop, then fall back to shutdownNow() if awaitTermination times out, ensuring the application doesn't hang indefinitely waiting for stuck tasks.
More Related questions...