Prevent launching multiple instances of a java application

前端 未结 10 2127
你的背包
你的背包 2020-12-03 03:19

I want to prevent the user from running my java application multiple times in parallel.

To prevent this, I have created a lock file when am opening the application,

10条回答
  •  旧巷少年郎
    2020-12-03 03:45

    You could write the process id of the process that created the lock file into the file. When you encounter an existing lock file, you do not just quit, but you check if the process with that id is still alive. If not, you can go ahead.

提交回复
热议问题