Saturday, November 9, 2013

Troubleshooting in Java

This post is just a collection of troubleshooting tips that I've picked up during the years.

Java processes

The easiest way to list Java processes is to use the jps utility that comes with JDK. It's similar to Linux ps command. Typically, you would use: jps -lv to list Java processes.

Then you can use the process PID to kill that process using the Windows taskkill utility.

Alternatively, you can use Process Explorer to list all processes running in Windows, which will also include Java processes. In addition, this utility lists environment variables of the processes, which is quite handy.

Monitoring remote Java processes running as Windows services

VisualVM and jConsole pick up Java processes that are running on the same JVM by the same user. Things become tricky when this is not the case. Java processes running as Windows services are run as the system user, and thus are not picked up by VisualVM by default, locally or remotely.

This is what worked for me for attaching VisualVM to a Java process running as Windows service.

  1. Login into the console session of the remote machine using for example: mstsc /console -v hostname
  2. Use the PsExec utilty from PsTools to run VisualVM as the system user:
    PsExec.exe -i -s jvisualvm.exe (Note: if this doesn't work, try full path: "C:\Program Files\Java\\bin\jvisualvm.exe")

No comments:

Post a Comment