How to Kill Java Process in Windows, WITHOUT killing javaw.exe?
Solution 1
I'd still suggest just killing the javaw.exe.
I can't see the downside, since it is the process you want to kill after all.
Remember that if you run multiple applications on the machine, they should each have a separate JVM instance. So you can still kill the specific application if you need to.
Solution 2
The JDK (and possibly the JRE) ship with a utility called jps which can list all Java processes but also tell you the Main-Class currently running in that JVM. If JMX/JConsole is not an option, simply parsing the output of "jps -ml" and killing the appropriate process may work.
Solution 3
If you want to kill an entire JVM, just kill the javaw.exe process. Within a JVM there can be multiple Java threads but there's no way to poke into a JVM and terminate a thread unless the developer of the application provided a method to do so.
Solution 4
Based on your comment, multiple javaw.exe programs are running and you need to know which one to kill.
You might want to try connecting to each of the processes with JConsole and inspect the JVM. There may be enough clues to determine which one to kill. Once you've identified the profile of your application, you should be able to script the logic to make it easier in the future (use JMX to get most of the information provided by JConsole).
Android Eve
Just starting in the world of Android development... New to Java and Eclipse as well.
Updated on June 04, 2022Comments
-
Android Eve almost 2 years
I have an external Windows .exe that is actually Java application: Running the .exe starts javaw.exe, which in turn runs that Java application.
I didn't write that application and have no access to it through an API. I need to be able to kill it, however. So right now I just kill the Windows process javaw.exe, which is fine for a test machine running only that Java application but if I need finer granularity, I cannot currently do so.
My searches yielded suggestions such as Sysinternal's Process Explorer or the jps command in the JDK, but in the target systems for which I intend to provide the script, neither JDK nor Sysinternal's Process Explorer can be running.
Is there any other way that doesn't require an external tool? Does javaw.exe have a switch or command line option that lists Java processes? Is there a JRE version of jps?
Thanks.
-
Android Eve over 13 yearsThank you both, Jim and @mikera -- +1 for both of you for explaining this issue to me. How would I know which javaw.exe to kill?
-
João dos Reis over 13 yearsCan't you look in Task Manager's Applications tab, then right-click on the relevant program and hit Go To Process. That'll give you the right javaw.exe.
-
Danny Thomas over 13 yearsWhat you need is a tool like Sysinternals Process Explorer. It'll allow you to see the parent processes and show you the full command line passed to javaw.exe.
-
Pacerier over 8 years@mikera, The downside is that on a server you affect the other Java apps by killing off the entire JVM.