Skip to content

Instantly share code, notes, and snippets.

@fxg42
Last active April 2, 2018 18:15
Show Gist options
  • Save fxg42/dd65f9151883b9baf4c215a275fb7dfe to your computer and use it in GitHub Desktop.
Save fxg42/dd65f9151883b9baf4c215a275fb7dfe to your computer and use it in GitHub Desktop.
JShell script to connect to JMX server
import javax.management.*
import javax.management.remote.*
var serverUrl = "service:jmx:rmi:///jndi/rmi://0.0.0.0:9090/jmxrmi"
var connection = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl)).getMBeanServerConnection()
var objectName = new ObjectName("my-domain:type=my-bean-type,name=my-bean-name")
var pingResult = (int) connection.invoke(objectName, "ping", null, null) // Assumes an `int ping()` method that returns the error code.
/exit pingResult
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment