Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross process synchronization in Java

How can I synchornize two Java processes running on Windows ?

I am looking for something like the Win32 Named Mutex object which allows two processes to use the same locking object.

Thanks

like image 482
Saar Avatar asked Mar 14 '11 11:03

Saar


1 Answers

I don't think there are native methods in the java platform for this. However, there are several ways to go about obtaining the same type of effect depending on what synchronization you are trying to accomplish. In addition to having the processes communicate over network connections (direct sockets, multicast with an election, etc.) or dropping to platform specific calls, you can also explore obtaining a file lock to a shared file (see activemq passive stand-by with a shared file system for an example) or using a database either with something like a select for update or an optimistic update of a table row.

like image 163
philwb Avatar answered Sep 30 '22 12:09

philwb