gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:58:15 24 4
gpt4 key购买 nike

我觉得这是我应该知道的事情,但是 java 代理(用 -javaagent 指定)是否在单独的线程中运行?我读过 a Java agent is a pluggable library that runs embedded in a JVM and intercepts the classloading process ,但我想确定:它是否真的拦截它们(这听起来像是在另一个线程中运行并监视类加载)或者它是否由 JVM 通知(JVM 调用它来解析类加载;没有单独的线程)?

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

谢谢!

最佳答案

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)

关于java - Java 代理是否在单独的线程中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3069677/

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