How it works...

In this recipe, you implemented the MyScheduledTask class to implement a custom task that can be executed on a ScheduledThreadPoolExecutor executor. This class extends the FutureTask class and implements the RunnableScheduledFuture interface. It implements the RunnableScheduledFuture interface because all the tasks executed in a scheduled executor must implement this interface and extend the FutureTask class. This is because this class provides valid implementations of the methods declared in the RunnableScheduledFuture interface. All the interfaces and classes mentioned earlier are parameterized classes and they possess the type of data that will be returned by the tasks.

To use a MyScheduledTask task in a scheduled executor, ...

Get Java 9 Concurrency Cookbook - Second 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.