Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting exclusive system-wide lock in Java

I'm re-working a Java executable that may be started multiple times, and I want the process to proceed one at a time. In C# I would do this with a named/system Mutex, but this doesn't seem to be possible in Java. How can I achieve this functionality?

like image 969
C. Ross Avatar asked Jul 07 '10 11:07

C. Ross


1 Answers

You can use exclusive access to a File on the File System to achieve similar behavior. I don't think there is something similar to what you've mentioned.

Examples

  • Java Programming [Archive] - open File in exclusive lock
  • java.nio.channels.FileLock
like image 157
Pablo Santa Cruz Avatar answered Oct 14 '22 13:10

Pablo Santa Cruz