O'Reilly logo

Mastering Concurrency Programming with Java 9 - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The advanced reader

The basic news reader is an example of the utilization of a ScheduledThreadPoolExecutor class, but we can go a step further. As occurs with ThreadPoolExecutor, we can implement our own ScheduledThreadPoolExecutor to obtain a particular behavior. In our case, we want the delay time of our periodic task changes to depend on the moment of the day. In this part, you will learn how to implement this behavior.

The first step is to implement a class that tells us the delay between two executions of a periodic task. We named this the Timer class. It only has a static method named getPeriod() that returns the number of milliseconds between the end of one execution and the start of the next one. This is our implementation, but ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required