There's probably other ways of doing this but I'd like to use an empty file to have one instance of an application running at a given time. This would be done by creating the file when the application is launched and have other application instances exit as soon as they detect the file.
The trouble with this approach is that the file can remain if the application stops unexpectedly and a ShutDownhook is proving unreliable.
How would you go about making this work as intended?