how to prevent one application from being executed more than once?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: how to prevent one application from being executed more than once?

  1. #1
    Join Date
    Dec 2004
    Posts
    2

    how to prevent one application from being executed more than once?

    Hi,

    how to prevent one application from being executed more than once in java?

    For example, AAA.class is a server application. After I run it by java AAA, I wish JVM forget it when it is executed again by java AAA.

    Thanks.

    Showla

  2. #2
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    There are various ways of doing this. One is to have a "lock" file that you look for at startup. If the lockfile is there, there is already an instance of your app running. The drawback is if your JVM died unexpectedly (force quit or something), then the lock file may still be there even with your app not running.

    Another is listening on a designated port on localhost. If at startup, you try to bind to a port, but there is already an app listening on that port, then do not start yourself. Instead, you could send your String[] params to the listening app. This has the advantage of allowing the working app to work on new stuff without having to reinitialize.

    A good example is a browser or editor or something.

    Similarly, but more platform specific, is listening on a Unix named pipe (mkfifo, etc).

    Hope this helps.

  3. #3
    Join Date
    Dec 2004
    Posts
    2
    Thank you very much, doredson

    It really helped me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center