Java: synchronizing threads across multiple servers

distributedjavajmsmultithreadingsynchronization

I have a problem where I need to synchronize processing for multiple threads across multiple different servers for a Java service on Windows.

In this application, I have multiple consumer threads pullings messages off the same JMS queue. Messages come in in groups of 3 or 4, and I need to make sure the messages in each group are processed completely in serial. I need some sort of synch mechanism to make sure if thread1 pulls a message off, then thread2 pulls the next message from that group, thread2 waits for thread1 to finish processing before starting to process it's message.

Any suggestions on distributed synching mechanisms for threads? Any type of solution would be good (JMS solutions, distributed caching, etc.)

Note: the JMS provider we're using is ActiveMQ.

Best Answer

ActiveMQ has support for message groups which, quite literally, should be exactly what you need.