1

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

Andrejs
  • 26,885
  • 12
  • 107
  • 96
  • Why not [JMX](https://docs.oracle.com/javase/8/docs/technotes/guides/jmx/index.html)? – apangin Apr 10 '18 at 09:14
  • Fair point, this is doable with JMX. My concern is 1) JMX needs to be enabled on the target JVM 2) Connecting to JMX is only possible from JVM languages, afaik. A jcmd can be invoked from small command line tools written in C, Go. – Andrejs Apr 10 '18 at 15:42

1 Answers1

2

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.
apangin
  • 92,924
  • 10
  • 193
  • 247