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?
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.
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