Does Java support any queue object or mechanism to handle batch treatment?
ex: we have a queue(or any desired queue object), some producer push item into the queue one by one, my target is when we have 10 items or more than 10 items in this queue, we can trigger some handler to treat it in one batch.
or it is not triggered automatically, we need to find a way to loop the queue gracefully at the handler side.
do we have typical and high performance object or lib to handle this?
thanks, Emre
Batch processing in Queue could be achievable with wait/notify, something like you would block thread call against the resource upto it is available or not.
public class MyQueue implements Queue<Object>{
public synchronized List<Object> peek() {
if(this.list.size()>=10)
this.list.wait();
return Collections.subList(0,10);
}
@Override
public boolean add(Object e) {
this.list.add(e);
if(this.list.size()>=10)
this.list.notifyAll();
return false;
}
}
it is not triggered automatically
In that case you can call wait with specified time out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With