Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if two instances of the same java program are running?

Tags:

java

Hi am making a program which will run through javaw.exe, so that it is not visible directly. Now my issue is sometime, (accidently) it can happen that the user runs multiple instances of the same application,

e.g entering javaw myProgram two times

Under such situation, is there any way i can prevent multiple instances of the same program to run if the program is already running.

like image 473
Sara Avatar asked Dec 21 '10 02:12

Sara


People also ask

How can you tell if two objects are the same instance?

Comparing objects with equals() In the first comparison, equals() compares the current object instance with the object that has been passed. If the two objects have the same values, equals() will return true .

What is multiple instance in Java?

Multi-instance (MI) classification is a supervised learning technique, but differs from normal supervised learning: it has multiple instances in an example. only one class label is observable for all the instances in an example.


1 Answers

Although file lock is probably the simplest and easiest option, I'd like to mention one alternative: JIntellitype is a library which works only on Windows and has the utility method to check if the application window with the given title is already running.

If it just so happens that you're OK with having this functionality only on Windows and using file lock doesn't work for you... :)

like image 51
Domchi Avatar answered Sep 23 '22 20:09

Domchi