PriorityQueue is an unbounded queue based on a priority heap and the elements of the priority queue are ordered by default in natural order or we can provide a Comparator for ordering at the time of instantiation of queue.
PriorityQueue doesn’t allow null values and we can’t create PriorityQueue of Objects that are non-comparable.
The head of the priority queue is the least element based on the natural ordering or comparator based ordering, if there are multiple objects with same ordering, then it can poll any one of them randomly.
PriorityQueue is not thread safe, so java provides PriorityBlockingQueue class that implements the BlockingQueue interface to use in java multi-threading environment. PriorityBlockingQueue uses ReentrantLock to ensure thread safety.
Read full article from Java Priority Queue (PriorityQueue) Example
PriorityQueue doesn’t allow null values and we can’t create PriorityQueue of Objects that are non-comparable.
The head of the priority queue is the least element based on the natural ordering or comparator based ordering, if there are multiple objects with same ordering, then it can poll any one of them randomly.
PriorityQueue is not thread safe, so java provides PriorityBlockingQueue class that implements the BlockingQueue interface to use in java multi-threading environment. PriorityBlockingQueue uses ReentrantLock to ensure thread safety.
Read full article from Java Priority Queue (PriorityQueue) Example