Java – why is PriorityQueue not like a queue?

I'm using priorityblockingqueue and priority fields In my tests, I used system #currenttime () as the priority - the computer gets the same priority so fast that the milliseconds are the same (or more like the milliseconds on the PC have an error margin)

When the priorities are the same, the queue looks like a stack, which seems strange When the priorities of elements are the same, is there an alternative method to make the queue behave like a normal queue (i.e. FIFO rather than LIFO)?

Solution

Priorityblockingqueue docs themselves tells you this and how to bypass it if you need to

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>