There's more...

The DelayQueue class has other interesting methods, which are as follows:

  • clear(): This method removes all the elements of the queue.
  • offer(E e): Here, E represents the class used to parameterize the DelayQueue class. This method inserts the element that is passed as a parameter into the queue.
  • peek(): This method retrieves but doesn't remove the first element of the queue.
  • take(): This method retrieves and removes the first element of the queue. If there aren't any active elements, the thread that is executing the method will be blocked until the thread gets some active elements.

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.