Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Ensure 1 running program  (Read 1021 times)
0 Members and 2 Guests are viewing this topic.
Offline nech_neb

Jr. Member
**

Posts: 57


Java for LIFE !!!


« on: 2003-11-27 17:41:04 »

Hi all,

I want to ensure that only 1 copy of my
program is running at once.

What is the suggested way of doing this?

Thanks in advance,
Much appriciated.
Offline Herkules

JGO Kernel
*****

Posts: 1522
Medals: 1


Friendly fire isn't friendly!


« Reply #1 on: 2003-11-27 23:16:42 »

hm - in win32 it is done with a named mutex.

Nothing can stop the user from starting another JVM .... maybe you can exploit the new properties API? Although this has to be handled with care, esp. concerning the shutdown procedure.

Just set a property saying that the program is already running and exit() if you find that the resp. property is already set.

Maybe a program should update that property every minute or so with a new timestamp. That could prevent from being unable to run just bc. a former instance crashed w/o removing the tag in the properties.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline swpalmer

JGO Kernel
*****

Posts: 3438
Medals: 4


Where's the Kaboom?


« Reply #2 on: 2003-11-28 06:45:58 »

Create a lock file in a known location.  If you can lock the file you are the only one of your app running.  be sure to delete it on exit, and or warn when starting that a previous instance may have crashed if the lock file is found.

Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.069 seconds with 19 queries.