title: queueing and batching requests using java
body: <p>I want to use some mechanism to do something like this - I have a application server getting request to process orders. One request can have one order or two orders. To process the order the application will need to make a call to outside vendor, vendor can process at the most 5 orders at a time. I want to create a component that will batch maximum up to 5 orders if available and fire one request to the vendor and then when I get the response re-distribute the reponse to the appropriate request. The component would wait, say, 2 seconds before firing a batch request ones the first request arrives. </p>
  
  <p>I thought of using JMS but in JMS a consumer will process the message (order) as soon as it arrives and a consumer processes one message at a time. I am thinking of usinga regular queue (ArrayBlockingQueue) and batch up the orders before firing using a ScheduledTimerTask. Does anybody have any ideas - Thanks in advance.</p>