Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to control the instances of my application

 
Ravi Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java application. I want to restrict the user to run the single instance of the application. How can i achieve this?
 
raimondas zemaitis
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nayanjyoti Talukdar
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I guess u wanna make a single instance of u'r application...For that matter, u can make use of singleton class.
---------
Nayan.
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic