Alex Rivera | Logout

How can I add a Javaagent to a JVM without stopping the JVM?

Asked 2011-01-27T14:36:28.937
26

I wish to profile a Java application without stopping the application. Can I add a Javaagent somehow while the application is running?

Edit
Report

1 Answer

7

It should be possible according the documentation of the java.lang.instrument package.

Starting Agents After VM Startup

An implementation may provide a mechanism to start agents sometime after the the VM has started. The details as to how this is initiated are implementation specific but typically the application has already started and its main method has already been invoked. In cases where an implementation supports the starting of agents after the VM has started the following applies:

1.The manifest of the agent JAR must contain the attribute Agent-Class. The value of this attribute is the name of the agent class.
2. The agent class must implement a public static agentmain method.
3. The system class loader ( ClassLoader.getSystemClassLoader) must support a mechanism to add an agent JAR file to the system class path.

but I have never tried it :-|

answered 2011-01-27T20:59:16.393

Your Answer