Name

ScheduledThreadPoolExecutor

Synopsis

This class extends ThreadPoolExecutor to implement the methods of the ScheduledExecutorService interface to allow tasks to be submitted for execution once or repeatedly at some scheduled time in the future. Instances of this class are usually obtained through the static factory methods of the Executors utility class. You can also explicitly create one with the ScheduledThreadPoolExecutors( ) constructor. ScheduledThreadPoolExecutor always creates its own unbounded work queue, which means that you cannot pass a queue to the constructor. Also, there is no need to specify a maximumPoolSize since this configuration parameter is irrelevant with unbounded queues.

Note that tasks submitted to a ScheduledThreadPoolExecutor are not guaranteed to run at the scheduled time. That is the time at which they first become eligible to run. If all threads are busy with other tasks, however, eligible tasks may get queued up to run later.

This class provides functionality similar to java.util.Timer but adds multithreaded capability and the ability to work with Callable and Future objects.

java.util.concurrent.ScheduledThreadPoolExecutor

Figure 16-91. java.util.concurrent.ScheduledThreadPoolExecutor

public class ScheduledThreadPoolExecutor extends ThreadPoolExecutor 
        implements ScheduledExecutorService {
// Public Constructors
     public ScheduledThreadPoolExecutor(int corePoolSize);  
     public ScheduledThreadPoolExecutor ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.