• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Stopping multiple launches of application

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a Windows batch file(.bat) which launches my GUI(Swing) application. I want to make sure only one copy of my application should be running at any time.
For example, assume that I have launched my application by running the batch file. Now if i try to execute the batch file it should not launch application and it should say something like "Application already running".

Please let me know how to achieve this.

Karthikeyan
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The application could open a ServerSocket on a particular port (say, 5000). If the second instance tries to do the same, it will get an exception, something like "port already in use".
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also write a temp file, there is a way to turn a �delete on exit flag� so your file will erase itself when your program exits. Every time you start your process you can try to find the file, if it exists you show your message and exit else you continue the normal way.
 
Always! Wait. Never. Shut up. Look at this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic