gpt4 book ai didi

java - 调试 Java 代理

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:57:56 26 4
gpt4 key购买 nike

我目前正在开发 Java Agent为了促进新旧 Java 应用程序的动态检测。

我突然想到,就 IDE 调试而言,Java 代理可能被认为是一种特殊情况,因为它们需要注入(inject)到目标 JVM 进程中才能运行。因此,这自然会引发一个问题,即如何调试、测试和分析代理类型的应用程序。

对现有解决方案的粗略搜索显示了一些基于命令行的选项(即 YourKit、JIP 等),但其中许多在底层也是 Java 代理。如果使用它,至少在我看来,会导致代理调试/分析另一个代理的相当奇怪的场景。我知道代理可以分层排列,但是我不确定代理应用程序是否可以通过在此庄园中堆叠代理来调试。

最佳答案

Java How To ... The -javaagent: Option 中所述:

An agent is just an interceptor in front of your main method, executed in the same JVM and loaded by the same system classloader, and governed by the same security policy and context.

The name is misleading, since the word agent usually suggests something working remotely and separately from the primary entity. But it turns out the java agent as used in -javaagent: is much simpler than that.

One java application may have any number of agents by using -javaagent: option any number of times. Agents are invoked in the same order as specified in options.

Each agent may also take String-valued args. I guess that's the reason why we have to use this option multiple times for multiple agents. Otherwise, we could've just done something like:

-javaagent agent1.jar:agent2.jar

, which is incorrect.

因此,通过将探查器代理(例如 YourKit、JIP 等)放在您自己的代理之前,您可以将调试控制权交给您。

关于java - 调试 Java 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17675518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com