2

Are there any efficient (without synchronize everything) implementations of java.util.concurrent.BlockingQueue that allow combining of entries?

By combining I mean to merge incoming item with existing "equal" entry on the queue (if there is one), otherwise item is added at the end as usual.

Dusan
  • 115
  • 1
  • 7
  • So, you mean a kind of Queue that behaves like a Set in that it doesn't allow duplicate elements? – Miquel Jul 16 '12 at 09:36

3 Answers3

2

Check this answer out: Concurrent Set Queue. It might be a duplicate of your question if all that you mean by merging is ignoring elements that are equal to something that's already on the queue.

Community
  • 1
  • 1
Miquel
  • 15,405
  • 8
  • 54
  • 87
1

BlockingQueue sports a contains method. Feel free to use it, but don't forget to synchronize. contains is O(n) f.x. in LinkedBlockingDeque, so you may try a more efficient approach with a HashSet.

Arne
  • 2,106
  • 12
  • 9
0

I can't see combining events if timestamp and source are two of its attributes. Unless the same user sent two events within a nanosecond or less of each other, I don't believe they can be considered equal and should not be combined.

duffymo
  • 305,152
  • 44
  • 369
  • 561