Using thread-safe lists with delayed elements

An interesting data structure provided by the Java API, which you can use in concurrent applications, is implemented in the DelayQueue class. In this class, you can store elements with an activation date. The methods that return or extract elements from the queue will ignore these elements whose data will appear in the future. They are invisible to these methods.To obtain this behavior, the elements you want to store in the DelayQueue class need to have the Delayed interface implemented. This interface allows you to work with delayed objects. This interface has the getDelay() method that returns the time until the activation of the element. This interface forces you to implement the following ...

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.