This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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...
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
Joined: Jun 15, 2005
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...
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
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?