ch to target VM VirtualMachine vm = VirtualMachine.attach("2177");
// get system properties in target VM Properties props = vm.getSystemProperties();
// construct path to management agent String home = props.getProperty("java.home"); String agent = home + File.separator + "lib" + File.separator + "management-agent.jar";
// load agent into target VM vm.loadAgent(agent, "com.sun.management.jmxremote.port=5000");
// detach vm.detach();
In this example we attach to a Java virtual machine that is identified by the process identifier 2177
. The system properties from the target VM are then used to construct the path to a management agent which is then loaded into the target VM. Once loaded the client detaches from the target VM.
A VirtualMachine is safe for use by multiple concurrent threads.
@since 1.6