Application example of delayqueue in Java multithreading concurrent development

In the process of learning java multithreading concurrent development, I learned that the delayqueue class is an unbounded BlockingQueue, which is used to place objects that implement the delayed interface. The objects can only be removed from the queue when they expire. This queue is ordered, that is, the delay expiration time of the queue head object is the longest. Note: null elements cannot be placed in this queue.

Delayed, a mixed style interface, is used to mark objects that should be executed after a given delay time. The implementation of this interface must define a CompareTo method that provides a sort consistent with the getdelay method of this interface.

I saw some examples on the Internet, found some problems in some examples, and made some modifications. I hope it can help you understand.

Chinese people like karaoke. Most people have a singer's dream in their heart. Especially when they were students, they like to go to KTV in groups to sing. They sing very well all afternoon. Speaking of the annual double 11, many single dogs began to come to KTV to sing. How does KTV charge and record time through the program at this time? The simulation code is as follows:

The results of the operation are as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>