O'Reilly logo

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

How it works...

In this recipe, we implemented the Event class. This class has a unique attribute, the activation date of the events, and it implements the Delayed interface. You can store Event objects in the DelayQueue class.

The getDelay() method returns the number of nanoseconds between the activation date and the actual date. Both dates are objects of the Date class. You used the getTime() method that returns a date converted into milliseconds. Then, you converted this value into TimeUnit, which was received as a parameter. The DelayQueue class works in nanoseconds, but at this point, it's transparent to you.

The compareTo() method returns a value less than zero if the delay of the object executing the method is smaller than the delay ...

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