标签:
protected Class<!--?--> loadClass(String name, boolean resolve)throws ClassNotFoundException{
//加上锁,同步处理,因为可能是多线程在加载类
synchronized (getClassLoadingLock(name)) {
//检查,是否该类已经加载过了,如果加载过了,就不加载了
Class c = findLoadedClass(name);
if (c == null) {
long t0 = System.nanoTime();
try {
//如果自定义的类加载器的parent不为null,就调用parent的loadClass进行加载类
if (parent != null) {
c = parent.loadClass(name, false);
} else {
//如果自定义的类加载器的parent为null,就调用findBootstrapClass方法查找类,就是Bootstrap类加载器
c = findBootstrapClassOrNull(name);
}
} catch (ClassNotFoundException e) {
// ClassNotFoundException thrown if class not found
// from the non-null parent class loader
}
if (c == null) {
// If still not found, then invoke findClass in order
// to find the class.
long t1 = System.nanoTime();
//如果parent加载类失败,就调用自己的findClass方法进行类加载
c = findClass(name);
// this is the defining class loader; record the stats
sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
sun.misc.PerfCounter.getFindClasses().increment();
}
}
if (resolve) {
resolveClass(c);
}
return c;
}
}
1 protected Class<!--?--> loadClass(String name, boolean resolve)throws ClassNotFoundException{ 2 //加上锁,同步处理,因为可能是多线程在加载类 3 synchronized (getClassLoadingLock(name)) { 4 //检查,是否该类已经加载过了,如果加载过了,就不加载了 5 Class c = findLoadedClass(name); 6 if (c == null) { 7 long t0 = System.nanoTime(); 8 try { 9 //如果自定义的类加载器的parent不为null,就调用parent的loadClass进行加载类 10 if (parent != null) { 11 c = parent.loadClass(name, false); 12 } else { 13 //如果自定义的类加载器的parent为null,就调用findBootstrapClass方法查找类,就是Bootstrap类加载器 14 c = findBootstrapClassOrNull(name); 15 } 16 } catch (ClassNotFoundException e) { 17 // ClassNotFoundException thrown if class not found 18 // from the non-null parent class loader 19 } 20 21 if (c == null) { 22 // If still not found, then invoke findClass in order 23 // to find the class. 24 long t1 = System.nanoTime(); 25 //如果parent加载类失败,就调用自己的findClass方法进行类加载 26 c = findClass(name); 27 28 // this is the defining class loader; record the stats 29 sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0); 30 sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1); 31 sun.misc.PerfCounter.getFindClasses().increment(); 32 } 33 } 34 if (resolve) { 35 resolveClass(c); 36 } 37 return c; 38 } 39 }
标签:
原文地址:http://www.cnblogs.com/hangtt/p/4853537.html