Search code examples
javawindowsmultithreading

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


Solution

  • It is not possible to do something like you want in Java. Different Java applications will use different JVM's fully separating themselves into different 'blackbox'es. However, you have 2 options:

    1. Use sockets (or channels). Basically one application will open the listening socket and start waiting until it receives some signal. The other application will connect there, and send signals when it had completed something. I'd say this is a preferred way used in 99.9% of applications.
    2. You can call winapi from Java. I do not remember the specifics, but you can find a plethora of example if you google "java winapi".