简体   繁体   中英

How to close the javax application if the same instance is already running?

I am running my java application by jar file. Now a certain need forces me to check other instance of same application running or not on same Machine. For eg i must restrict to run only one instance of application to make run, close other application (if running on other tab on terminal). I have searched similar threats from here , but actually unable to figure out.

The easiest way to achieve this would be to create a lock-file when you start your application. When you start a second instance it can check for the existence of such a file and terminate if one is found. When you close the first instance it has to delete this file of course before it finally terminates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM