I have a Java application. I want to restrict the user to run the single instance of the application. How can i achieve this?
Joined: Feb 23, 2001
a simple way to do this is to create temporary file in known location (user profile could be used for this) when application starts and delete it on exit. App should check if file exists prior to creation.
Joined: Feb 12, 2002
Hi, I guess u wanna make a single instance of u'r application...For that matter, u can make use of singleton class. --------- Nayan.
Joined: May 25, 2001
the singelton pattern only prevents one instance of a class inside the same classloader/inside the same VM. If you start an application (trough: java com.some.MyApp) then you start an new VM and the classes are loaded with a new classloader. the problem with the temp file is that after a crash of the app the temp file might stay on the disk and a restart of the app wont work because the file is present (perhaps the running app could rewrite the file every X seconds or so and if you start the app you check if the file is present AND NOT older that X seconds). Looks ugly to me but i dont have another idea.... good luck