shutdown() stops the pool from accepting new tasks but still runs everything already queued to completion. Only after awaitTermination confirms that is it safe to read state the tasks wrote.
ExecutorService pool = Executors.newFixedThreadPool(1);
List<Integer> completed = new ArrayList<>();
pool.submit(() -> completed.add(1));
pool.submit(() -> completed.add(2));
pool.shutdown();
pool.awaitTermination(1, TimeUnit.SECONDS);
System.out.println("Completed after shutdown(): " + completed);
Completed after shutdown(): [1, 2]
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27