• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to stop running multiple instances of jar?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys! I am in trouble. I created program using Java. Exported into JAR. When I started my jar file, program works, ok. But when I try to launch again without closing previous one, then it runs. So how to disable this?

P.S: My English is poor.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One trick that's often used is for your program to try to open a ServerSocket on a specific port. If it succeeds, then go ahead and run the application. If it fails, then immediately exit. This way, only one copy of your application can run at a time. You can try to do similar things by creating a temporary file and checking for its existence, but this is harder to get right, especially on Windows.
 
enkhbat dash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So this is the only way. :!:
reply
    Bookmark Topic Watch Topic
  • New Topic