如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM? [英] How can I add a Javaagent to a JVM without stopping the JVM?

查看:23
本文介绍了如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在不停止应用程序的情况下分析 Java 应用程序.我可以在应用程序运行时以某种方式添加 Javaagent 吗?

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

推荐答案

根据java.lang.instrument 包.

虚拟机启动后启动代理

一个实现可能会提供一种机制来在某个时候启动代理虚拟机启动后.这关于如何启动的详细信息是特定于实现的,但通常应用程序已经开始了,它的主要方法有已经被调用了.在这种情况下一个实现支持VM 启动后代理的启动开始以下适用:

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.agent JAR的manifest必须包含属性代理级.这个的价值属性是代理的名称上课.
2.代理类必须实现一个公共静态agentmain方法.
3.系统类加载器(ClassLoader.getSystemClassLoader)必须支持添加代理的机制JAR 文件到系统类路径.

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.

但我从未尝试过 :-|

这篇关于如何在不停止 JVM 的情况下将 Javaagent 添加到 JVM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆