java JVM-线程上下类加载器

public class One {

public static void main(String[] args) throws Exception {

    ClassLoader loader=One.class.getClassLoader();
    System.out.println(loader);

    //获得当前线程的上下文加载器,未改变前和第一种是一样的
    ClassLoader loader2=Thread.currentThread().getContextClassLoader();
    System.out.println(loader2);

    //修改当前线程的上下文修改器
    Thread.currentThread().setContextClassLoader(new Loader("d:/myjava"));
    System.out.println(Thread.currentThread().getContextClassLoader());
    Class<Dema> c=(Class<Dema>) Thread.currentThread().getContextClassLoader().loadClass("cn.sxt.in.Dema");
    System.out.println(c);
    System.out.println(c.getClassLoader()); //因为定义了父类委派机制,所以还是app加载
 }
}
上一篇:JavaWeb学习篇之----EL表达式详解


下一篇:ReentrantLock底层原理、手写Lock锁