Card 09/ 09
Recap: Executors and Futures
Pools, the two task types, blocking get, shutdown, and the pool that keeps a process alive.
Executors and futures come down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
| A pool separates what work there is from which thread runs it | Thread Pools: Handing Work to a Fixed Set of Threads |
Callable returns a value and may throw; Runnable does neither | Runnable vs Callable |
get() blocks, so submit everything before collecting anything | Future.get(): Why Calling It Too Early Removes the Overlap |
shutdown asks, awaitTermination waits, shutdownNow insists | Shutting Down an ExecutorService Without Losing Work |
| A pool nobody shuts down keeps the process alive with nothing to do | Unclosed Thread Pools: Why a Program Hangs After main Returns |
Submitting is not running, and getting is waiting. Almost every disappointing result from a thread pool is one of those two facts forgotten at a call site.
← → move through sections and cards