From the course: Parallel and Concurrent Programming with Java 2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Thread pool: Java demo

Thread pool: Java demo - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 2

Start my 1-month free trial

Thread pool: Java demo

- [Instructor] To create thread pools in Java, I'll be using the ExecutorService interface, which is defined in the java.util.concurrent package. It serves as a higher level interface for launching new runnable tasks rather than working with threads directly. And it includes several features to help manage the lifecycle of individual tasks as well as the executor itself. Under the hood, the executor service manages a pool of threads, so we don't have to create new threads manually. The executor maintains a queue of the tasks that get submitted to it and then it uses the existing threads in its thread pool to run those tasks asynchronously. The executors class provides several factory methods for creating different kinds of executor services. Two of the most common methods are the new single thread executor, which creates an executor that reuses a single worker thread to execute the tasks that are submitted to its queue and the new fixed thread pool method, which creates a thread pool…

Contents