Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One instance of application running

 
Javeo Lineo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I have an application and I want to ensure that only one instance of it is run, how do I do it? If an instance is already running, and the user executes another one, the application will prompt a message to the user, indicating another instance is already running...
 
Sri Ram
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kinda Application is this?? Windows Application or Web Application??

Windows Application -- > Keep a text file for storing a variable say Application Status, Update this when the application is opened. say Started.
When the user shutsdown,update it back to Stopped. And access this file every time u start the application and also begin only if the status is Stopped.

Web Application ---> Have a cookie
 
Javeo Lineo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sri Ram ,

what kind of application is this?? its a standalone application / J2SE, it
runs on a UNIX OS...

the application wil ensure that only one instance of it will run, If an instance is already running, and the user executes another one, the application will prompt a message to the user, indicating another instance is already running...

thanks for the reply, greatly appreacited...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instanciate a ServerSocket on a specific port. Only one application can do this - all others will get an IOException when trying. And the port is automatically freed when the application exits - even if the VM should crash or something...
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree, the server socket is the way to go. The file solution is asking
for trouble -- what if the program crashes and leaves the file behind
in the wrong state, or the user deliberately edits or deletes the file when
he shouldn't?
 
Javeo Lineo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To Ilja Preuss, Jeff Albrechtsen and Sri Ram

Thanks for the reply, greatly appreacited...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic