- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经创建了一个 java 代理 jar 文件(在命令行上运行完美)。接下来,我想将此代理附加到 j2ee 服务器中正在运行的 JVM。所以我使用了代码:
public static void loadAgent() {
System.out.println("dynamically loading javaagent");
String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
int p = nameOfRunningVM.indexOf('@');
String pid = nameOfRunningVM.substring(0, p);
try {
VirtualMachine vm = VirtualMachine.attach(pid);
String jarFilePath = vm.getSystemProperties().getProperty("java.home")+File.separator+"lib"+File.separator+"test-agent-7.jar";
vm.loadAgent(jarFilePath, "");
vm.detach();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
编辑:现在可以正常工作了,我可以看到调用了 Transformer。我还可以移除变压器并能够调试变压器。
我的问题是:
最佳答案
好吧,有几件事需要考虑:
如果加载代理,则加载类。只要相关的类加载器在 Java VM 的内存中,相关的类就会保持加载状态。我不认为你可以轻易地预防/规避。但这应该只是很小的内存开销,您可以通过加载代理来解决。
一些研究表明代理将由 SystemClassLoader 加载,因此无法卸载这些类。
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: The manifest of the agent JAR must contain the attribute Agent-Class. The value of this attribute is the name of the agent class. The agent class must implement a public static agentmain method. The system class loader ( ClassLoader.getSystemClassLoader) must support a mechanism to add an agent JAR file to the system class path. Link to source
但是,您可以影响的是代理正在做什么。
您想关闭该代理吗?提供关机方法。
如果您想从外部停止代理,该代理可以提供一个 JMXBean 来关闭代理。
此方法然后可以从 Instrumentation 接口(interface)中删除转换器或停止代理在 Java VM 中执行的任何其他操作(释放引用/持有的资源,以便对象被垃圾收集,类似这样的东西)。
如果不更具体地说明您想要实现的目标,就很难给出更合适的答案。
关于java - 如何在代码中动态添加 Java Agents jar 后卸载它们? Java 检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18057504/
功能介绍 agent.exe程序文件是一个类似Windows更新服务(wuauclt.exe,即Windows Update)的程序,它不是Windows系统的一部分。而是第三方软件公司发布的程序
我正在尝试查找 android 应用程序的用户代理。 该应用程序允许应用程序内浏览,所以我认为它必须有一个用于浏览的用户代理。 我怎么知道那是什么?我正在尝试使用该信息来运行该网站的桌面版本,使其看起
考虑以下代码: (let [slave-agent (agent 0) run-slave (fn [_] (println "running slave agent")) run-m
我最近遇到了“多代理计算”这个术语,但我不太明白它是什么。我读过一本关于它的书,但这并没有回答代理是什么的基本问题。 是否有人有指向一些引用的指针,该引用清晰简洁,并且在没有大量废话/营销言论的情况下
我有一个 java 代理,我可以从它调用另一个代理,通过它传递包含 NoteId 的参数,并使用该 NoteId,我能够成功地完成该文档的工作。直到这里一切都清楚了. 关于此的主要问题是,是否可以从当
SQL Server 2012 SP2 CU6 v-5592 我启动 SQL 服务和 SQL 代理服务;都开始OK。然后我在 Windows 2012 Ent(不是 R2)服务器上登录 SSMS,SQ
有一个应用程序我曾经在 Mozilla 中运行,但我决定使用 Chrome。我选择了BlahBlahBlahSafari.gwt.xml (包含 )在 Google/GWT Compile 的帮助下
这与我的第一个问题有关。我更新了所有代码。在我的 bot.js是: require('dotenv').config(); let ver = process.env.DISCORD_BOT; cli
在 OPA 中,很清楚如何查询 condition AND condition : values := { "value1": { "a": "one" }, "value2":
通过 User-Agent header 检测设备是否为 SmartTV 设备的任何常用方法/模式?可能正在搜索 TV 或其他内容? 请告知还有其他值得检测的电视相关平台吗? UPD:根据这个http
这就是我跑步时它返回给我的东西。我试图更新包,但仍然不起作用。我也试过重新安装Julia,这个包在重新安装后只会运行一次。然后我第二次跑步的时候。它将再次失败。我试着修复它已经很长时间了。。有人能帮我
我是 OPA(开放策略代理)的新手,正在尝试使用 REST API/v1/policies/{id} 创建新策略。有用!但是,OPA 服务器将其保存到内存中,并且在重新启动后我的所有策略都被删除了。我
我想在 K8sPSPCapabilities 约束模板中将一个容器列入白名单,但我在使用 rego 语言时遇到了一些困难。我想禁止除特定容器之外的所有容器的 NET_RAW 功能。如果有人能指出我正确
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
导入命令: “从rasa_core.agent导入代理” 给我以下错误 ----------------------------------------------------------------
我正在为 Eclipse Kepler 开发一个插件。将 @RunWith(JMockit.class) 添加到我的测试类会导致以下错误: JMockit: Reinitializing un
如何使用TD-AGENT-BIT将日志文件作为消息输出,可以是逐行输出,也可以是以“hh:mm:ss”开头的行输出,然后向下游发送,而不是每次一起输出多行日志?日志:。。。我想要下面这样的消息:。。。
我在 SQL Server 上有一个非常奇怪的情况,我无法理解。 环境:SQL Server 2012 SP3 CU3 在 2 节点 Windows 2008 R2 集群上运行 在 SQL Serve
有关该主题的所有其他问题都没有解决我的问题。 注入(inject)器: VirtualMachine vm = VirtualMachine.attach(pid); vm.loadAgent(new
[SSH]“无法打开与您的身份验证代理的连接”。错误 我正在尝试将 ssh key 添加到我的 ssh 代理中。我首先确保 ssh-agent 正在运行。 exec ssh-agent bash 我确
我是一名优秀的程序员,十分优秀!