Cover by Javier Fernández González

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Using thread-safe lists with delayed elements

An interesting data structure provided by the Java API, and that you can use in concurrent applications, is implemented in the DelayedQueue class. In this class, you can store elements with an activation date. The methods that return or extract elements of the queue will ignore those elements whose data is in the future. They are invisible to those methods.

To obtain this behavior, the elements you want to store in the DelayedQueue class have to implement the Delayed interface. This interface allows you to work with delayed objects, so you will implement the activation date of the objects stored in the DelayedQueue class as the time remaining until the activation date. This interface forces to implement ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required