Process control My jar name

I wanted to know if there is a way to control the name of the process that the jar starts, i.e.,
I created a .jar file in java and whenever I click on it, it calls a process named javaw.exe and I want manage this name. I want to do this because when I click on my jar file then if it is already running it should stop and a new one should start i.e. I want to start a new thread (process) every time I click on it, stopping the previous one.If I kill a process named javaw.exe, all processes named javaw.exe will die (if I have more than one program running). Therefore, I need to change its name. Plz help. Thank!

+3


source to share


3 answers


There is nothing wrong with working javaw

. From the documentation :

The javaw command is identical to java, except that there is no console window associated with javaw. Use javaw when you don't want a command prompt window to appear. However, the javaw launcher displays an error dialog box if for some reason it is unable to launch.



Ultimately javaw

runs your program without a console window. Changing this name can lead to serious problems later, so you want to keep that specific program name.

+2


source


Why reinvent the wheel? There are already standard ways to prevent two copies of the same program. This usually involves creating a "flag" file because file systems ensure that directory updates are atomic. On UNIX-like systems, the file will be / var / run / program -name.pid. If it already exists, then the second copy will fail.



+1


source


You can set up a controller process that manages your instances:

First you try to connect to a localhost hosting controller via tcp / ip on a specific port (your program names are "from now on"), and if that succeeds, you send a "new instance" message to that controller. If the connection fails, you start a new controller thread in the current vm (and post the message to that thread again).

controller loops waiting for messages and if one of them matches "new instance started" it does what you describe.

such a controller can be easily built using a simple ServerSocket server, a small HTTP server, or many other messaging libraries.

0


source







All Articles