Prevent launching multiple instances of a java application

前端 未结 10 2105
你的背包
你的背包 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:44

    I see two options you can try:

    1. Use a Java shutdown hook
    2. Have your lock file hold the main process number. The process should exist when you lanuch another instance. If it's not found in your system, you can assume that the lock can be dismissed and overwritten.

提交回复
热议问题