当前位置: 移动技术网 > IT编程>开发语言>Java > 【java】【16】双亲委派

【java】【16】双亲委派

2020年07月27日  | 移动技术网IT编程  | 我要评论

1.rt包的源码下载

2.加载类的继承

AppClassLoader的父类是ExtClassLoader
AppClassLoader的父类是在sun.misc.Launcher初始化的时候指定的
ExtClassLoader的父类是BootstrapClassLoader
BootstrapClassLoader不是java实现的,找不到实现类

java.lang.ClassLoader
public class SecureClassLoader extends ClassLoader {
public class URLClassLoader extends SecureClassLoader implements Closeable {
public class Launcher {
	static class ExtClassLoader extends URLClassLoader{}
	static class AppClassLoader extends URLClassLoader{}
}

3.三个加载类的路径

类加载路径

BootstrapClassLoader
sun.boot.class.path
ExtClassLoader
java.ext.dirs
AppClassLoader
java.class.path

任意找一个应用启动

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

	public static void main(String[] args) {
		
		System.out.println("-----sun.boot.class.path"+System.getProperty("sun.boot.class.path"));
		
		System.out.println("-----java.ext.dirs"+System.getProperty("java.ext.dirs"));
		
		System.out.println("-----java.class.path"+System.getProperty("java.class.path"));	
		
		 new SpringApplicationBuilder(EurekaApplication.class).web(true).run(args);
	}

}

输出结果

 -----sun.boot.class.pathD:\Program Files\Java\jdk1.8.0_191\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar;D:\Program Files\Java\jdk1.8.0_191\jre\lib\sunrsasign.jar;D:\Program Files\Java\jdk1.8.0_191\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_191\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_191\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_191\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_191\jre\classes
-----java.ext.dirsD:\Program Files\Java\jdk1.8.0_191\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
-----java.class.pathD:\project\git\zhenzhenaizlx\springcloud-demo-eureka-Brixton\target\classes;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-starter-eureka-server\1.1.0.RELEASE\spring-cloud-starter-eureka-server-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-starter\1.1.0.RELEASE\spring-cloud-starter-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter\1.3.5.RELEASE\spring-boot-starter-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot\1.3.5.RELEASE\spring-boot-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\spring-context\4.2.6.RELEASE\spring-context-4.2.6.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-autoconfigure\1.3.5.RELEASE\spring-boot-autoconfigure-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-logging\1.3.5.RELEASE\spring-boot-starter-logging-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\ch\qos\logback\logback-classic\1.1.7\logback-classic-1.1.7.jar;D:\soft\apache-maven-3.6.3\repo\ch\qos\logback\logback-core\1.1.7\logback-core-1.1.7.jar;D:\soft\apache-maven-3.6.3\repo\org\slf4j\jcl-over-slf4j\1.7.21\jcl-over-slf4j-1.7.21.jar;D:\soft\apache-maven-3.6.3\repo\org\slf4j\jul-to-slf4j\1.7.21\jul-to-slf4j-1.7.21.jar;D:\soft\apache-maven-3.6.3\repo\org\slf4j\log4j-over-slf4j\1.7.21\log4j-over-slf4j-1.7.21.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\spring-core\4.2.6.RELEASE\spring-core-4.2.6.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\yaml\snakeyaml\1.16\snakeyaml-1.16.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-context\1.1.0.RELEASE\spring-cloud-context-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\security\spring-security-crypto\4.0.4.RELEASE\spring-security-crypto-4.0.4.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-commons\1.1.0.RELEASE\spring-cloud-commons-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\security\spring-security-rsa\1.0.1.RELEASE\spring-security-rsa-1.0.1.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\bouncycastle\bcpkix-jdk15on\1.47\bcpkix-jdk15on-1.47.jar;D:\soft\apache-maven-3.6.3\repo\org\bouncycastle\bcprov-jdk15on\1.47\bcprov-jdk15on-1.47.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-netflix-eureka-server\1.1.0.RELEASE\spring-cloud-netflix-eureka-server-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-web\1.3.5.RELEASE\spring-boot-starter-web-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-tomcat\1.3.5.RELEASE\spring-boot-starter-tomcat-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\apache\tomcat\embed\tomcat-embed-core\8.0.33\tomcat-embed-core-8.0.33.jar;D:\soft\apache-maven-3.6.3\repo\org\apache\tomcat\embed\tomcat-embed-el\8.0.33\tomcat-embed-el-8.0.33.jar;D:\soft\apache-maven-3.6.3\repo\org\apache\tomcat\embed\tomcat-embed-logging-juli\8.0.33\tomcat-embed-logging-juli-8.0.33.jar;D:\soft\apache-maven-3.6.3\repo\org\apache\tomcat\embed\tomcat-embed-websocket\8.0.33\tomcat-embed-websocket-8.0.33.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-validation\1.3.5.RELEASE\spring-boot-starter-validation-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\hibernate\hibernate-validator\5.2.4.Final\hibernate-validator-5.2.4.Final.jar;D:\soft\apache-maven-3.6.3\repo\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;D:\soft\apache-maven-3.6.3\repo\org\jboss\logging\jboss-logging\3.3.0.Final\jboss-logging-3.3.0.Final.jar;D:\soft\apache-maven-3.6.3\repo\com\fasterxml\classmate\1.1.0\classmate-1.1.0.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\spring-web\4.2.6.RELEASE\spring-web-4.2.6.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\spring-aop\4.2.6.RELEASE\spring-aop-4.2.6.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\spring-beans\4.2.6.RELEASE\spring-beans-4.2.6.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\spring-webmvc\4.2.6.RELEASE\spring-webmvc-4.2.6.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\spring-expression\4.2.6.RELEASE\spring-expression-4.2.6.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-actuator\1.3.5.RELEASE\spring-boot-starter-actuator-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-actuator\1.3.5.RELEASE\spring-boot-actuator-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\boot\spring-boot-starter-freemarker\1.3.5.RELEASE\spring-boot-starter-freemarker-1.3.5.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\freemarker\freemarker\2.3.23\freemarker-2.3.23.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\spring-context-support\4.2.6.RELEASE\spring-context-support-4.2.6.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-netflix-core\1.1.0.RELEASE\spring-cloud-netflix-core-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-netflix-eureka-client\1.1.0.RELEASE\spring-cloud-netflix-eureka-client-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\eureka\eureka-client\1.4.6\eureka-client-1.4.6.jar;D:\soft\apache-maven-3.6.3\repo\org\codehaus\jettison\jettison\1.3.7\jettison-1.3.7.jar;D:\soft\apache-maven-3.6.3\repo\stax\stax-api\1.0.1\stax-api-1.0.1.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\netflix-commons\netflix-eventbus\0.3.0\netflix-eventbus-0.3.0.jar;D:\soft\apache-maven-3.6.3\repo\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\servo\servo-core\0.10.1\servo-core-0.10.1.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\servo\servo-internal\0.10.1\servo-internal-0.10.1.jar;D:\soft\apache-maven-3.6.3\repo\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\soft\apache-maven-3.6.3\repo\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\soft\apache-maven-3.6.3\repo\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\soft\apache-maven-3.6.3\repo\org\apache\httpcomponents\httpclient\4.5.2\httpclient-4.5.2.jar;D:\soft\apache-maven-3.6.3\repo\org\apache\httpcomponents\httpcore\4.4.4\httpcore-4.4.4.jar;D:\soft\apache-maven-3.6.3\repo\commons-codec\commons-codec\1.9\commons-codec-1.9.jar;D:\soft\apache-maven-3.6.3\repo\com\google\inject\guice\4.0\guice-4.0.jar;D:\soft\apache-maven-3.6.3\repo\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\governator\governator-api\1.12.10\governator-api-1.12.10.jar;D:\soft\apache-maven-3.6.3\repo\com\sun\jersey\jersey-servlet\1.19.1\jersey-servlet-1.19.1.jar;D:\soft\apache-maven-3.6.3\repo\com\sun\jersey\jersey-server\1.19.1\jersey-server-1.19.1.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\eureka\eureka-core\1.4.6\eureka-core-1.4.6.jar;D:\soft\apache-maven-3.6.3\repo\com\amazonaws\aws-java-sdk-core\1.10.30\aws-java-sdk-core-1.10.30.jar;D:\soft\apache-maven-3.6.3\repo\com\amazonaws\aws-java-sdk-ec2\1.10.30\aws-java-sdk-ec2-1.10.30.jar;D:\soft\apache-maven-3.6.3\repo\com\amazonaws\aws-java-sdk-autoscaling\1.9.3\aws-java-sdk-autoscaling-1.9.3.jar;D:\soft\apache-maven-3.6.3\repo\com\amazonaws\aws-java-sdk-sts\1.9.3\aws-java-sdk-sts-1.9.3.jar;D:\soft\apache-maven-3.6.3\repo\com\amazonaws\aws-java-sdk-route53\1.9.3\aws-java-sdk-route53-1.9.3.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\governator\governator\1.12.10\governator-1.12.10.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\governator\governator-core\1.12.10\governator-core-1.12.10.jar;D:\soft\apache-maven-3.6.3\repo\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\soft\apache-maven-3.6.3\repo\org\codehaus\woodstox\woodstox-core-asl\4.4.1\woodstox-core-asl-4.4.1.jar;D:\soft\apache-maven-3.6.3\repo\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\archaius\archaius-core\0.7.4\archaius-core-0.7.4.jar;D:\soft\apache-maven-3.6.3\repo\com\google\code\findbugs\jsr305\3.0.1\jsr305-3.0.1.jar;D:\soft\apache-maven-3.6.3\repo\javax\inject\javax.inject\1\javax.inject-1.jar;D:\soft\apache-maven-3.6.3\repo\com\fasterxml\jackson\dataformat\jackson-dataformat-xml\2.6.6\jackson-dataformat-xml-2.6.6.jar;D:\soft\apache-maven-3.6.3\repo\com\fasterxml\jackson\module\jackson-module-jaxb-annotations\2.6.6\jackson-module-jaxb-annotations-2.6.6.jar;D:\soft\apache-maven-3.6.3\repo\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;D:\soft\apache-maven-3.6.3\repo\com\thoughtworks\xstream\xstream\1.4.2\xstream-1.4.2.jar;D:\soft\apache-maven-3.6.3\repo\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;D:\soft\apache-maven-3.6.3\repo\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-starter-archaius\1.1.0.RELEASE\spring-cloud-starter-archaius-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\soft\apache-maven-3.6.3\repo\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\soft\apache-maven-3.6.3\repo\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;D:\soft\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-annotations\2.6.6\jackson-annotations-2.6.6.jar;D:\soft\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-core\2.6.6\jackson-core-2.6.6.jar;D:\soft\apache-maven-3.6.3\repo\com\fasterxml\jackson\core\jackson-databind\2.6.6\jackson-databind-2.6.6.jar;D:\soft\apache-maven-3.6.3\repo\com\google\guava\guava\18.0\guava-18.0.jar;D:\soft\apache-maven-3.6.3\repo\org\springframework\cloud\spring-cloud-starter-ribbon\1.1.0.RELEASE\spring-cloud-starter-ribbon-1.1.0.RELEASE.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\ribbon\ribbon\2.1.5\ribbon-2.1.5.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\ribbon\ribbon-transport\2.1.5\ribbon-transport-2.1.5.jar;D:\soft\apache-maven-3.6.3\repo\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;D:\soft\apache-maven-3.6.3\repo\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\hystrix\hystrix-core\1.5.2\hystrix-core-1.5.2.jar;D:\soft\apache-maven-3.6.3\repo\org\hdrhistogram\HdrHistogram\2.1.7\HdrHistogram-2.1.7.jar;D:\soft\apache-maven-3.6.3\repo\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;D:\soft\apache-maven-3.6.3\repo\io\netty\netty-codec-http\4.0.27.Final\netty-codec-http-4.0.27.Final.jar;D:\soft\apache-maven-3.6.3\repo\io\netty\netty-codec\4.0.27.Final\netty-codec-4.0.27.Final.jar;D:\soft\apache-maven-3.6.3\repo\io\netty\netty-handler\4.0.27.Final\netty-handler-4.0.27.Final.jar;D:\soft\apache-maven-3.6.3\repo\io\netty\netty-transport-native-epoll\4.0.27.Final\netty-transport-native-epoll-4.0.27.Final.jar;D:\soft\apache-maven-3.6.3\repo\io\netty\netty-common\4.0.27.Final\netty-common-4.0.27.Final.jar;D:\soft\apache-maven-3.6.3\repo\io\netty\netty-buffer\4.0.27.Final\netty-buffer-4.0.27.Final.jar;D:\soft\apache-maven-3.6.3\repo\io\netty\netty-transport\4.0.27.Final\netty-transport-4.0.27.Final.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\ribbon\ribbon-core\2.1.5\ribbon-core-2.1.5.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\ribbon\ribbon-httpclient\2.1.5\ribbon-httpclient-2.1.5.jar;D:\soft\apache-maven-3.6.3\repo\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\netflix-commons\netflix-commons-util\0.1.1\netflix-commons-util-0.1.1.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\ribbon\ribbon-loadbalancer\2.1.5\ribbon-loadbalancer-2.1.5.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;D:\soft\apache-maven-3.6.3\repo\io\reactivex\rxjava\1.1.5\rxjava-1.1.5.jar;D:\soft\apache-maven-3.6.3\repo\com\netflix\ribbon\ribbon-eureka\2.1.5\ribbon-eureka-2.1.5.jar;D:\soft\apache-maven-3.6.3\repo\org\slf4j\slf4j-api\1.7.21\slf4j-api-1.7.21.jar

4.sun.misc.Launcher类的部分代码

/**
 * This class is used by the system to launch the main application.
Launcher */
public class Launcher {

	private static String bootClassPath =
        System.getProperty("sun.boot.class.path");

	private ClassLoader loader;
	
	public Launcher() {
        // Create the extension class loader
        ClassLoader extcl;
        try {
            extcl = ExtClassLoader.getExtClassLoader();
        } catch (IOException e) {
            throw new InternalError(
                "Could not create extension class loader", e);
        }

        // Now create the class loader to use to launch the application
        try {
            loader = AppClassLoader.getAppClassLoader(extcl);
        } catch (IOException e) {
            throw new InternalError(
                "Could not create application class loader", e);
        }

    }
	
	static class AppClassLoader extends URLClassLoader {
	
		public static ClassLoader getAppClassLoader(final ClassLoader extcl)
				throws IOException
		{
			final String s = System.getProperty("java.class.path");
			final File[] path = (s == null) ? new File[0] : getClassPath(s);

			// Note: on bugid 4256530
			// Prior implementations of this doPrivileged() block supplied
			// a rather restrictive ACC via a call to the private method
			// AppClassLoader.getContext(). This proved overly restrictive
			// when loading  classes. Specifically it prevent
			// accessClassInPackage.sun.* grants from being honored.
			//
			return AccessController.doPrivileged(
				new PrivilegedAction<AppClassLoader>() {
					public AppClassLoader run() {
					URL[] urls =
						(s == null) ? new URL[0] : pathToURLs(path);
					return new AppClassLoader(urls, extcl);
				}
			});
		}
		
		/*
		 * Creates a new AppClassLoader
		 */
		AppClassLoader(URL[] urls, ClassLoader parent) {
			super(urls, parent, factory);
		}
		
		/**
		 * Override loadClass so we can checkPackageAccess.
		 */
		public Class<?> loadClass(String name, boolean resolve)
			throws ClassNotFoundException
		{
			int i = name.lastIndexOf('.');
			if (i != -1) {
				SecurityManager sm = System.getSecurityManager();
				if (sm != null) {
					sm.checkPackageAccess(name.substring(0, i));
				}
			}
			return (super.loadClass(name, resolve));
		}

	}
	
	static class ExtClassLoader extends URLClassLoader {
		 /**
         * create an ExtClassLoader. The ExtClassLoader is created
         * within a context that limits which files it can read
         */
        public static ExtClassLoader getExtClassLoader() throws IOException
        {
            final File[] dirs = getExtDirs();

            try {
                // Prior implementations of this doPrivileged() block supplied
                // aa synthesized ACC via a call to the private method
                // ExtClassLoader.getContext().

                return AccessController.doPrivileged(
                    new PrivilegedExceptionAction<ExtClassLoader>() {
                        public ExtClassLoader run() throws IOException {
                            int len = dirs.length;
                            for (int i = 0; i < len; i++) {
                                MetaIndex.registerDirectory(dirs[i]);
                            }
                            return new ExtClassLoader(dirs);
                        }
                    });
            } catch (java.security.PrivilegedActionException e) {
                throw (IOException) e.getException();
            }
        }
		
		private static File[] getExtDirs() {
            String s = System.getProperty("java.ext.dirs");
            File[] dirs;
            if (s != null) {
                StringTokenizer st =
                    new StringTokenizer(s, File.pathSeparator);
                int count = st.countTokens();
                dirs = new File[count];
                for (int i = 0; i < count; i++) {
                    dirs[i] = new File(st.nextToken());
                }
            } else {
                dirs = new File[0];
            }
            return dirs;
        }
	
	}


}

5.java.lang.ClassLoader.loadClass的方法

/**
 * Loads the class with the specified <a href="#name">binary name</a>.  The
 * default implementation of this method searches for classes in the
 * following order:
 *
 * <ol>
 *
 *   <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
 *   has already been loaded.  </p></li>
 *
 *   <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
 *   on the parent class loader.  If the parent is <tt>null</tt> the class
 *   loader built-in to the virtual machine is used, instead.  </p></li>
 *
 *   <li><p> Invoke the {@link #findClass(String)} method to find the
 *   class.  </p></li>
 *
 * </ol>
 *
 * <p> If the class was found using the above steps, and the
 * <tt>resolve</tt> flag is true, this method will then invoke the {@link
 * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
 *
 * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
 * #findClass(String)}, rather than this method.  </p>
 *
 * <p> Unless overridden, this method synchronizes on the result of
 * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
 * during the entire class loading process.
 *
 * @param  name
 *         The <a href="#name">binary name</a> of the class
 *
 * @param  resolve
 *         If <tt>true</tt> then resolve the class
 *
 * @return  The resulting <tt>Class</tt> object
 *
 * @throws  ClassNotFoundException
 *          If the class could not be found
 */
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;
	}
}

6.修改bootstrap路径

https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
windows以;分割,unix以:分割

-Xbootclasspath:path
Specifies a list of directories, JAR files, and ZIP archives separated by colons (:) to search for boot class files. These are used in place of the boot class files included in the JDK.

Do not deploy applications that use this option to override a class in rt.jar, because this violates the JRE binary code license.

-Xbootclasspath/a:path
Specifies a list of directories, JAR files, and ZIP archives separated by colons (:) to append to the end of the default bootstrap class path.

Do not deploy applications that use this option to override a class in rt.jar, because this violates the JRE binary code license.

-Xbootclasspath/p:path
Specifies a list of directories, JAR files, and ZIP archives separated by colons (:) to prepend to the front of the default bootstrap class path.

Do not deploy applications that use this option to override a class in rt.jar, because this violates the JRE binary code license.

本文地址:https://blog.csdn.net/huiyanshizhen21/article/details/107591291

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网