aspose file tools*
The moose likes Java in General and the fly likes Running Single Instance of application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Running Single Instance of application

satyam vizag narayana
Greenhorn

Joined: Jul 07, 2006
Posts: 8
Hi,

I developed a swing based application in java. I am running it through the executable jar. Each time clicking on the jar file it opens the new instance of the appliction.

But I want to open the single instance of the application i.e. If the application is running , then user tries to open another instance it should be display the error or running application only like yahoomessenger,notepad,etc.

Please tell me how it is done in java. send aly sample code or resources regarding this.

Thanks
in advance
aslam parveez
Ranch Hand

Joined: Apr 25, 2006
Posts: 47
I dont know what kind of application you are talking about.

One way of doing it is , Create a ServerSocket object just before your window is made visible.
For ex: ServerSocket serverSocket=new ServerSocket(5555);

If the application is already running and if you try to run it again then typically you should get an error saying "Port already in Use".
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Please don't post the same question in multiple forums. It creates duplicate conversations and wastes the time of the people trying to help you.

Thanks,
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Single Instance of application