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

后端 未结 4 707
猫巷女王i
猫巷女王i 2020-11-30 11:08

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

4条回答
  •  自闭症患者
    2020-11-30 11:46

    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 :-|

提交回复
热议问题