Other methods of interest
Throughout the pages of this chapter, we have used some classes of the Java concurrency API to implement basic functionalities of the executor framework. These classes also have other interesting methods. In this section, we collate some of them.
The Executors
class provides other methods to create ThreadPoolExecutor
objects. These methods are:
newCachedThreadPool()
: This method creates aThreadPoolExecutor
object that reuses a worker-thread if it's idle, but it creates a new one if it's necessary. There is no maximum number of worker-threads.newSingleThreadExecutor()
: This method creates aThreadPoolExecutor
object that uses only a single worker-thread. The tasks you send to the executor are stored in a queue until the worker-thread can execute them.- The
CountDownLatch
class provides the following additional methods:await(long timeout, TimeUnit unit)
: It waits till the internal counter arrives to zero of pass the time specified in the parameters. If the...