java- how to wait constantly for an event to happen

java

Solution

`BlockingQueue` and its implementation `LinkedBlockingQueue` can be useful here.

When `Thread` will want to `take` something from queue by calling

queue.take() 

and queue will be empty, such thread will wait until other thread will put something into queue by calling

queue.put(something). 

Also if queue is full, `queue.put()` will make putting thread wait until there will be room in queue for new elements.

Problem

I am creating an application in which there are multiple stages- for each stage a message is sent to my queue in Amazon Simple Work Flow (SWF)... The app should start a new thread for each message that is received. How do I implement the waiting part- so that the application constantly scans the queue for new messages and takes action the moment a message is received?

Original source