views:

27

answers:

1

Hi all, I'm trying to implement a Consumer/Producer app in Grails, after several unsuccessful attempts at implementing concurrent threads. Basically I want to store all the events coming from a clients (through separate AJAX calls) in a single queue and then process such a queue in a linear way as soon as new events are added.

This looks like a Producer/Consumer problem: http://en.wikipedia.org/wiki/Producer-consumer_problem

How can I implement this in Grails (maybe with a timer or even better by generating an event 'process queue')?

Basically I'd like to a have a singleton service waiting for new events in the queue and processing them linearly (even if the queue is loaded by several concurrent processes).

Any hints?

Cheers!

+1  A: 

Rather than implement it all yourself, I would recommend using Java Messaging Service. It handles exactly the type of problem you are talking about. Further, Grails has a JMS plugin.

Sun Docs on JMS: http://java.sun.com/developer/technicalArticles/Ecommerce/jms/index.html

Grails JMS Plugin: http://www.grails.org/JMS+Plugin

Mike