java代理是否在单独的线程中运行?

发布于 2024-09-06 00:52:49 字数 327 浏览 6 评论 0原文

我觉得这是我应该知道的事情,但是java代理(用-javaagent指定)是否在单独的线程中运行?我读过 Java 代理是一个可插入库,它嵌入在 JVM 中运行并拦截类加载过程,但我想确定:它真的拦截它们(听起来像是在另一个线程中运行并监视类加载)还是由 JVM 通知( JVM 调用它来解析类加载;没有单独的线程)?

再次,我感觉我应该能够弄清楚,但是对我好一点,我工作太努力了,我的大脑有点烧焦了:P

谢谢!

I feel that this is something I should know, but does a java agent (specified with -javaagent) run in a separate thread? I've read that a Java agent is a pluggable library that runs embedded in a JVM and intercepts the classloading process, but I want to make sure: does it really intercept them (which sounds like it's running in another thread and monitoring class loads) or is it notified by the JVM (the JVM invokes it to resolve the class load; there isn't a separate thread for it)?

Again, I get the feeling that I should be able to figure it out, but be nice to me, I'm working too hard and my brain is kinda fried :P

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫负雪 2024-09-13 00:52:50

ClassFileTransformer 由 ClassLoader 调用。对您链接的文章中的变压器进行一些修改,如下所示:

public byte[] transform(ClassLoader loader, String className,
        Class redefiningClass, ProtectionDomain domain, byte[] bytes)
        throws IllegalClassFormatException {
    new RuntimeException("Transformer to Transform Class: " + className)
            .printStackTrace(System.out);
    return bytes;
}

产生以下输出:

java.lang.RuntimeException: Transformer to Transform Class: MyMain
    at com.javalobby.tnt.instrument.SimpleTransformer.transform(SimpleTransformer.java:14)
    at sun.instrument.TransformerManager.transform(Unknown Source)
    at sun.instrument.InstrumentationImpl.transform(Unknown Source)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)

The ClassFileTransformer gets invoked by the ClassLoader. A little modification of the transformer from the article you linked, to look like this:

public byte[] transform(ClassLoader loader, String className,
        Class redefiningClass, ProtectionDomain domain, byte[] bytes)
        throws IllegalClassFormatException {
    new RuntimeException("Transformer to Transform Class: " + className)
            .printStackTrace(System.out);
    return bytes;
}

yields this output:

java.lang.RuntimeException: Transformer to Transform Class: MyMain
    at com.javalobby.tnt.instrument.SimpleTransformer.transform(SimpleTransformer.java:14)
    at sun.instrument.TransformerManager.transform(Unknown Source)
    at sun.instrument.InstrumentationImpl.transform(Unknown Source)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文