There's more...

The PriorityBlockingQueue class has other interesting methods. The following is a description of some of them:

  • clear(): This method removes all the elements of the queue.
  • take(): This method returns and removes the first element of the queue. If the queue is empty, it blocks its thread until the queue has elements.
  • put(E e): This is the class used to parameterize the PriorityBlockingQueue class. It inserts the element that is passed as a parameter into the queue.
  • peek(): This method returns the first element of the queue but doesn't remove it.

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.