I have a pool of threads which are fed tasks from a queue. Generally, a small number of threads are able to keep the queue empty. Occasionally, a particularly large burst of events will keep the queue size above zero for some time, but not for long.
My concern is regarding events that are duplicates or carry data that obsoletes previous events. During times of high volume, such events can coexists in the queue for a short period of time. I would like to be able to conflate these so that I can reduce time spent doing wasted work.
What is a good way to conflate such a queue? I could conflate at insertion time by iterating from back to head and searching for a candidate to replace, however this seems too brute-force. If you have code or library recommendations, please keep in mind that I am using Java.