Module lessons (1/2)
ExecutorService and CompletableFuture
Separate tasks from threads with pools ExecutorService, asynchronous pipelines CompletableFuture, ConcurrentHashMap, and AtomicInteger.
What you'll learn in this lesson
- Run concurrent tasks on managed thread pools via
ExecutorServicewithout creating disposable threads. - Collect future results with
Futureand always release workers withshutdown(). - Compose non-blocking asynchronous pipelines with
CompletableFuture,thenApply,thenCombineandexceptionally.
Overview
Manually creating new Thread(...).start() for each request consumes native stack memory and makes the number of active threads uncontrollable. In modern Java, you separate tasks from worker threads via ExecutorService, and combine asynchronous streams with CompletableFuture.
A ExecutorService maintains a fixed or elastic pool of ready threads. submit() accepts a Callable<T> or Runnable and immediately returns a Future<T> to query when the result is needed:
Sections covered in this lesson
- 11. Thread Pool with
ExecutorServiceandFuture - 22. Asynchronous Pipelines with
CompletableFuture - 33. Combine Two Streams and Handle Asynchronous Errors
- 44. Shared State:
AtomicIntegeragainst Race Condition - 5Try it yourself
Unlock "ExecutorService and CompletableFuture" and the full Course Java curriculum
Separate tasks from threads with pools `ExecutorService`, asynchronous pipelines `CompletableFuture`, `ConcurrentHashMap`, and `AtomicInteger`.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course Java plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.