zoukankan      html  css  js  c++  java
  • Java的类加载器种类(双亲委派)

    Java类加载器采用双亲委派模型:

    TIM截图20170926111521

    1.启动类加载器:这个类加载器负责放在<JAVA_HOME>lib目录中的,或者被-Xbootclasspath参数所指定的路径中的,并且是虚拟机识别的类库。用户无法直接使用。

    2.扩展类加载器:这个类加载器由sun.misc.Launcher$AppClassLoader实现。它负责<JAVA_HOME>libext目录中的,或者被java.ext.dirs系统变量所指定的路径中的所有类库。用户可以直接使用。

    3.应用程序类加载器:这个类由sun.misc.Launcher$AppClassLoader实现。是ClassLoader中getSystemClassLoader()方法的返回值。它负责用户路径(ClassPath)所指定的类库。用户可以直接使用。如果用户没有自己定义类加载器,默认使用这个。

    4.自定义加载器:用户自己定义的类加载器。

    protected Class<?> loadClass(String name, boolean resolve)
            throws ClassNotFoundException
        {
            synchronized (getClassLoadingLock(name)) {
                // First, check if the class has already been loaded
                Class<?> c = findLoadedClass(name);
                if (c == null) {
                    long t0 = System.nanoTime();
                    try {
                        if (parent != null) {
                            c = parent.loadClass(name, false);
                        } else {
                            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();
                        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;
            }
        }
    

      

  • 相关阅读:
    转:SQL Case when 的使用方法
    转:性能测试知多少
    转:如何让LoadRunner实现多个场景运行?
    转:Loadrunner学习知多少--脚本录制下载操作
    1.3 本章小结
    1.2.5 内部元数据
    1.2.4 创建图像查看应用程序
    1.2.3 使用MediaStore检索图像
    1.2.2 更新CameraActivity以使用MediaStore存储图像和关联元数据
    1.2.1 获得图像的Uri
  • 原文地址:https://www.cnblogs.com/jay-wu/p/10144452.html
Copyright © 2011-2022 走看看