请看以下代码:public class Test {
public static void main(String[] args) {
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
Thread.currentThread().setContextClassLoader(systemLoader.getParent());
System.out.println(Thread.currentThread().getContextClassLoader());
Test t = new Test();
System.out.println(t.getClass().getClassLoader());
}
}输出结果如下:sun.misc.Launcher$ExtClassLoader@addbf1
sun.misc.Launcher$AppClassLoader@19821f
我的问题是:
我在main方法的当前线程已经设置了类加载器为ExtClassLoader,那么创建Test对象的时候,为什么还是AppClassLoader加载了呢?
书上说如果设定了当前线程的加载器,那么当前线程在加载类的时候,都会采用设定好的加载器啊。
所以创建Test对象的时候应该打印ExtClassLoader才对啊,为什么还会是AppClassLoader呢?
谢谢大家!
public static void main(String[] args) {
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
Thread.currentThread().setContextClassLoader(systemLoader.getParent());
System.out.println(Thread.currentThread().getContextClassLoader());
Test t = new Test();
System.out.println(t.getClass().getClassLoader());
}
}输出结果如下:sun.misc.Launcher$ExtClassLoader@addbf1
sun.misc.Launcher$AppClassLoader@19821f
我的问题是:
我在main方法的当前线程已经设置了类加载器为ExtClassLoader,那么创建Test对象的时候,为什么还是AppClassLoader加载了呢?
书上说如果设定了当前线程的加载器,那么当前线程在加载类的时候,都会采用设定好的加载器啊。
所以创建Test对象的时候应该打印ExtClassLoader才对啊,为什么还会是AppClassLoader呢?
谢谢大家!
解决方案 »
- Struts2整合出现500错,刚学struts2,在线等,帮忙看看
- spring 使用错误.
- jsp开发环境配置
- 超连接中参数的意思?及%5B@,%3D%27,%27%5D 这些字符是怎么转换的啊?
- urlwirte问题
- 关于BEAN的错误,50分求教!!
- 请问如何用Java Servlet或Jsp上传图像文件并把该图像保存到数据库中去,谢了!
- 分布式数据库
- BUG!!用jspSmartUpload上传文件出现的怪事!!!
- IIS与TOMCAT绑定后,为什么<a href="d.jsp?name=中国">连接</a>
- birt查询出来的coed值转换成value值,怎么做
- 自己弄的一个Struts1实例,总是访问不到action 求大侠指点指点
sun.misc.Launcher$ExtClassLoader@addbf1中的@后面的几个字符是什么。
第二,一般情况下,设定类加载器有什么用处?