From the course: Java SE 21 Developer (1Z0-830) Cert Prep

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

ExecutorService and Future

ExecutorService and Future

- Okay, now we're going to investigate the ExecutorService and using Future. At the operating system level, threads tend to be expensive to create and there's no reason they have to die just because they've executed a single task. The concept of a thread pool allows a modest number of threads to work on a very large number of short-lived tasks over a long period. Tasks will be submitted to a queue, and when a worker thread completes a previous task, it pulls the next available task from the queue. The core Java APIs provide executor and ExecutorService implementations for this purpose. The most basic thread pool interface is the executor. This defines a single method called execute, which takes a runnable as an argument and returns void. More interestingly, perhaps, the sub interface of that ExecutorService is quite a lot more capable. It allows returning a result from a job to the jobs submitter, determining the…

Contents