Does java have a concurrent queue with a fixed size that can automatically determine when a new element is inserted at the end of the queue. If the queue is full, poll will drop the element at the end of the queue, and if it is not full, offer will enter?
Ps: LinkedBlockingQueue considered
But the efficiency is not too high. . . )
Moreover, since element e is a business bean, it is relatively large, so the time for 100 concurrency is about 300 ~ 400 ms. . . .
Seek better solutions from the Great God. . .
ArrayBlockingQueue should meet the requirements of LZ, but it still needs to judge by the return value of offer.
The size of ConcurrentLinkedQueue is not a constant time operation, so it is slow. LinkedBlockingQueue is implemented with linked lists, and it is not specially used for fixed-size queues, so it is also slow.