how to prevent one application from being executed more than once?
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.
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.
Thank you very much, doredson
It really helped me.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL