jcmd - Handle custom commands in running JVM

380 Views Asked by At

The jcmd utility offers multiple diagnostic commands: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html

Is it possible to have custom commands and handle them in the running JVM?

Something like: jcmd $PID myCmd

1

There are 1 best solutions below

0
On BEST ANSWER

jcmd handles only a list of predefined JVM commands. However, there are multiple ways to implement custom management commands without jcmd.

  1. The simple one is just to open a socket inside JVM for listening to incoming control messages.
  2. Alternatively you can use Dynamic Attach mechanism to load an agent library into the running JVM process. There are both Java API and native interface for doing that.