Ensure 1 running program

Hi all,

I want to ensure that only 1 copy of my
program is running at once.

What is the suggested way of doing this?

Thanks in advance,
Much appriciated.

hm - in win32 it is done with a named mutex.

Nothing can stop the user from starting another JVM … maybe you can exploit the new properties API? Although this has to be handled with care, esp. concerning the shutdown procedure.

Just set a property saying that the program is already running and exit() if you find that the resp. property is already set.

Maybe a program should update that property every minute or so with a new timestamp. That could prevent from being unable to run just bc. a former instance crashed w/o removing the tag in the properties.

Create a lock file in a known location. If you can lock the file you are the only one of your app running. be sure to delete it on exit, and or warn when starting that a previous instance may have crashed if the lock file is found.