jpwallen
asked on
Global Windows Mutex in Java
I am looking to create a Mutex in Java that will prevent someone from running through a piece of code on the ENTIRE machine. The Mutex needs to extend beyond the VM and I would like to use the Win32 native Mutex since all the clients are going to be Windows anyway. After searching I saw something about "sun.jkernel.Mutex" namespace but I can't seem to find that on our JDK (Java7).
Can anyone suggest a class to use or does anyone know if the Mutex class changed to something else?
Can anyone suggest a class to use or does anyone know if the Mutex class changed to something else?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Ended up using a native EXE to create mutexes.
If you want access to a Win32 native Mutex, I'd suggest calling that API directly through JNI (Java Native Interface).
That may sound a bit intimidating if you've not dealt with it before, but it's actually not much code to write, esp if you're familiar with C/C++.
There's a tutorial here: http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html
Doug