Class RemoteRecordingStream

java.lang.Object
jdk.management.jfr.RemoteRecordingStream
All Implemented Interfaces:
AutoCloseable, EventStream

public final class RemoteRecordingStream extends Object implements EventStream
An implementation of an EventStream that can serialize events over the network using an MBeanServerConnection.

The following example shows how to record garbage collection pauses and CPU usage on a remote host and print the events to standard out.

     
     String host = "com.example";
     int port = 4711;

     String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";

     JMXServiceURL u = new JMXServiceURL(url);
     JMXConnector c = JMXConnectorFactory.connect(u);
     MBeanServerConnection conn = c.getMBeanServerConnection();

     try (var rs = new RemoteRecordingStream(conn)) {
         rs.enable("jdk.GCPhasePause").withoutThreshold();
         rs.enable("jdk.CPULoad").withPeriod(Duration.ofSeconds(1));
         rs.onEvent("jdk.CPULoad", System.out::println);
         rs.onEvent("jdk.GCPhasePause", System.out::println);
         rs.start();
     }
     
 
Since:
16