Link to home
Create AccountLog in
Avatar of jpwallen
jpwallenFlag for United States of America

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?
Avatar of dpearson
dpearson

I'm not aware of that being supported within Java itself since it inherently breaks the JVM sandbox model - not usually something Java is looking to do.

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
ASKER CERTIFIED SOLUTION
Avatar of jpwallen
jpwallen
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jpwallen

ASKER

Ended up using a native EXE to create mutexes.