ExecutorService
The standard-library service that owns a pool of worker threads and runs tasks you submit to it, returning a Future for each.
In more detail
Submitting tasks to an executor separates what to run from how threads are managed. The pool limits how many tasks run at once, and its queue holds the rest. Whoever creates an executor owns it and must call shutdown, otherwise its threads can keep the process alive.
Examples
ExecutorService pool = Executors.newFixedThreadPool(2);pool.shutdown();Related terms
- thread pool — A fixed or bounded set of reusable worker threads that take tasks from a queue, instead of creating a new thread for each task.
- Future — An object representing the result of a task that may not have finished yet; get waits for it.
- Callable — The functional interface for a task that returns a result and may throw an exception, submitted to an executor.
- bounded queue — A waiting line for tasks with a maximum size, so that when it is full new work is rejected instead of piling up in memory.
- CompletableFuture — A Future that can be completed later and chained, letting you describe asynchronous steps such as transform, combine and recover without nesting callbacks.
Taught in
- Concurrency Basics: Threads And Runnable — Modern Java: Virtual Threads & High-Throughput Services
- The ExecutorService — Modern Java: Virtual Threads & High-Throughput Services
- Async With CompletableFuture — Modern Java: Virtual Threads & High-Throughput Services
- Jars, Automatic Modules And Runtime Images — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Platform And Virtual Threads, Runnable And Callable — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Modules And Concurrency — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Mock Exam: Sit It, Score It — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep