☕ Java Intermediate

What is the Executor framework in Java?

Answer

The Executor framework (in java.util.concurrent) provides a high-level replacement for manually creating and managing threads. Instead of new Thread(runnable).start(), you submit tasks to an executor: executor.submit(runnable). The framework decouples task submission from execution policy. ExecutorService manages thread pools. Factory methods in Executors: newFixedThreadPool(n) (n reusable threads), newCachedThreadPool() (grows as needed), newSingleThreadExecutor() (one thread, serial execution), newScheduledThreadPool() (for delayed/periodic tasks). Always shut down executors when done: executor.shutdown().