0

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?

casgage
  • 529
  • 1
  • 7
  • 18
  • "Using a lock file would work but is not pretty." <-- why? It works fine... Though you'll have to use the new file API to get reliable results (Java 6 cannot do `O_CREAT|O_EXCL`) – fge Mar 15 '14 at 12:38
  • Using a lock resource of some sort is the standard solution. Opening a network port might be an alternative to a file, if you don't mind tying up a relatively scarce system resource. The only use for shutdownhooks I see here is to make sure the the lock gets unlocked when you exit. – keshlam Mar 15 '14 at 15:19

0 Answers0