Executors and Thread Pools
45 min · Advanced
A thread pool keeps a fixed set of worker threads and feeds them tasks from a queue, so you submit work instead of creating threads. Interviewers expect you to know the executor types, what each ThreadPoolExecutor parameter does, and how to shut a pool down. Section 10, Executors & Thread Pools, taught this; this lesson is the revision.
Topics in this lesson
- Why thread pools: the cost of threads
- Executor types and ThreadPoolExecutor parameters
- submit vs execute; shutdown vs shutdownNow
- CompletableFuture and ConcurrentHashMap in one minute
- Traps: forgetting shutdown and unbounded queues
Interview questions this lesson answers
- What is a thread pool?
- Why are thread pools better than creating threads manually?
- What is the Executor framework?
- What is the difference between Executor and ExecutorService?
- What types of thread pools does the Executors class provide?
- When would you use a cached thread pool?
- What are the parameters of ThreadPoolExecutor?
- How does ThreadPoolExecutor decide what to do with a new task?
- What are the rejection policies?
- How do you choose the pool size?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.