Possible Duplicates:
How to implement a single instance Java application?
How do I make sure only one instance of my program can be executed?
What is a good and easy way to achieve this? I've read methods involving binding to a port. Will this interfere with other applications using the same method?
Not good to bind to a port. Try starting the application and resetting the network adapter, see what happens. Other applications could also need to use that port.
I think it's better to implement a lock on an external resource, such as a file, but care must be taken: if the pc reboots or something like that, it will be necessary to detect the stale locks.
Have you checked the Apache commons or JBoss projects yet? i bet there must be a library to do this correctly.
Only if they use the same port, and there are a lot of ports. Just don't use one of the common ones.
Some software will also use some sort of lock file. Thus a second instance won't start if it exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With