From the course: Java SE 17 Developer (1Z0-829) Cert Prep

Unlock this course with a free trial

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

ExecutorService lifecycle, part 1

ExecutorService lifecycle, part 1 - Java Tutorial

From the course: Java SE 17 Developer (1Z0-829) Cert Prep

ExecutorService lifecycle, part 1

- Now let's look at the lifecycle of an executor service. Several implementations of executor service are available. The executor's class has a bunch of factories for things like newFixedThreadPool, which has a certain number of threads fixed within it. A newSingleThreadExecutor, which has exactly one thread and just runs jobs one after the other, a newCachedThreadPool. That makes more threads in times of high load and lets a thread die if it goes unused for a long enough time. We also have the ScheduledThreadPool, which have a subinterface with more features for running jobs after delays or perhaps repeatedly. And the ThreadPoolExecutor class is perhaps the most general, which has all kinds of parameterizations that are possible. There's also a scheduled ThreadPoolExecutor class, and the ForkJoinPool. Thread pools, including the ones we just looked at, can vary in several ways. One aspect is the input queue size. That is to say how big the queue is and how many jobs can be waiting…

Contents