Possible duplicate: How to implement a single instance application in Java
There are two methods I know of for creating single instance applications.
- Listen on a port at 127.0.0.1. This has a problem: if another app using this same method chooses to use the same port, it will not be able to open when my app does.
- Create a lock file, and either impose a system wide file lock, or write something to the file. There's also a major issue with this one: if the JVM crashes the program may not remove the file locks it previously imposed, thus forcing you to delete the lock file to start the program once more.
Are some of these problems not real? Is there a reliable method of doing such a thing?
I know .NET provides system-wide mutexes, however Java lacks something like this.