aspose file tools*
The moose likes Beginning Java and the fly likes One instance of application running Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "One instance of application running" Watch "One instance of application running" New topic
Author

One instance of application running

Javeo Lineo
Greenhorn

Joined: Jun 15, 2005
Posts: 6
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

Joined: Oct 03, 2005
Posts: 118
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

Joined: Jun 15, 2005
Posts: 6
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

Joined: Jul 11, 2001
Posts: 14112
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...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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?


There is no emoticon for what I am feeling!
Javeo Lineo
Greenhorn

Joined: Jun 15, 2005
Posts: 6
To Ilja Preuss, Jeff Albrechtsen and Sri Ram

Thanks for the reply, greatly appreacited...
 
wood burning stoves
 
subject: One instance of application running