• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Only one application in the Memory

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody,
I am building a desktop application. The thing is that I don't want 2 references to the program in the memory, so the 2nd time the program tries to start it just doesn't start.
I though of the following not working solution:
Create a starter-class.
This class should load the main-app class, built as a singleton.
This didn't work, I think that every time the application is loaded, it will get a amount of memory, and isn't allowed to look into the other applications memory.
Does any have a solution to this problem?
I have been thinking about setting a flag using Preferences, and reading this out. But I think that when the application crashes or something like that, and the value isn't put back the way it is done when it is closed, the application couldn't be started anymore.
Does someone have a better solution?
Regards,
Mark Monster
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One trick (and I say trick because it is not an elegant solution) is to use a known system resource. The easiest is probably to open a java.net.ServerSocket on an unused port. Then if the application is loaded a second time then a BindException will be thrown when you try to bind the ServerSocket to the port. For example:
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic