I have two processes (producer/consumer). The first one puts elements in a Collection, the second one reads them.
I want the second process not to read every individual element, but wait until:
- There are at least N elements in the collection OR
- The last element was received T seconds ago.
Is there any Collection in Java 5+ that allows this kind of behaviour? I was thinking about an implementation of Queue, but I’ve only found DelayQueue that is not exactly what I need.
Thank you.
I’d implement an observable collection. The second process will listen to events, signalling that
Nelements are in the collection (events based onsizeattribute) and that no element has been added for a certain time (needs a timer, that is reset on everyaddoperation)Something like this (just drafting the size requirement):