From the course: Advanced Java: Threads and Concurrency

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Managing thread execution: Thread pools and executors

Managing thread execution: Thread pools and executors - Java Tutorial

From the course: Advanced Java: Threads and Concurrency

Managing thread execution: Thread pools and executors

- [Instructor] Creating, managing, and destroying threads is expensive. This statement might not make much sense to you at first. Let's think about it like this. If a company needs subject matter experts for their projects from time to time, hiring them permanently and paying them high salaries and benefits and maintaining them and then firing them would be expensive. Instead, if the company could use the services of a consultancy firm that maintains a pool of expert consultants who can be hired whenever required, it'll be much more cost effective. Similarly, a thread pool is a group of threads that can be used to execute tasks rather than creating, managing, and destroying them every time a task needs to be executed. Threads in a thread pool are reusable. This means that the same thread can be used to execute more than one task. Tasks can be allocated to available threads, and once they are done with the assigned task, they'll be back in the pool available for another task. This is…

Contents