I see various posts on this subject but no conclusive answers except for a C# way.
Using a lock file would work but is not pretty.
I saw reference to using a shutdownhook, but without any elaboration. After combing the API doc of the Runtime class, I was not able to work out how. I have used shutdownhook before but only for its advertized functionality. Can anyone show me a snippet for the above purpose?