Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: synchronizing threads across multiple servers

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.

like image 289
Andy White Avatar asked Apr 03 '09 21:04

Andy White


People also ask

How are threads synchronized in Java?

Thread Synchronization is a process of allowing only one thread to use the object when multiple threads are trying to use the particular object at the same time. To achieve this Thread Synchronization we have to use a java keyword or modifier called “synchronized”.


1 Answers

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

like image 60
andri Avatar answered Sep 23 '22 01:09

andri