In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to understand Java class loader and class loading mechanism". The content of the article is simple and clear, and it is easy to learn and understand. please follow the editor's train of thought to study and learn "how to understand Java class loader and class loading mechanism".
A little bit of eye contact
The class 1 loader is responsible for loading .class files (either on disk or on the network) into memory and generating the corresponding java.lang.Class objects for them.
2 when JVM starts, an initial classloader hierarchy consisting of three classloaders is formed:
Bootstrap ClassLoader: root class loader.
Extension ClassLoader: extend the classloader.
System ClassLoader: system class loader.
3 the class loading mechanism of JVM mainly has the following three mechanisms:
Overall responsibility: overall responsibility means that when a class loader is responsible for loading a Class, other Class that the Class depends on and references will also be loaded by the class loader, unless explicitly loaded by another class loader.
Parent delegate: the so-called parent delegate is to have the parent (parent) classloader try to load the Class first, and try to load the class from its own classpath only if the parent loader cannot load the class.
Caching mechanism: the caching mechanism will ensure that all loaded Class will be cached. When a certain Class is needed in the program, the class loader first searches the cache for the Class. Only when the Class object does not exist in the cache, the system will read the corresponding binary data of this class, convert it into Class objects, and store it in cache. This is why after we have modified Class, the program must restart JVM for the changes made by the program to take effect.
Second actual combat
1 code
Import java.net.*;public class BootstrapTest {public static void main (String [] args) {/ / get all the URL array URL [] urls = sun.misc.Launcher loaded by the root class loader. GetBootstrapClassPath (). GetURLs (); / / traverses and outputs all URL for loaded by the root class loader (int I = 0; I < urls.length; iTunes +) {System.out.println (urls [I]. ToExternalForm ());}
2 run
File:/D:/Program/Java/jdk1.8.0_162/jre/lib/resources.jarfile:/D:/Program/Java/jdk1.8.0_162/jre/lib/rt.jarfile:/D:/Program/Java/jdk1.8.0_162/jre/lib/sunrsasign.jarfile:/D:/Program/Java/jdk1.8.0_162/jre/lib/jsse.jarfile:/D:/Program/Java/jdk1.8.0_162/jre/lib/jce. Jarfile:/D:/Program/Java/jdk1.8.0_162/jre/lib/charsets.jarfile:/D:/Program/Java/jdk1.8.0_162/jre/lib/jfr.jarfile:/D:/Program/Java/jdk1.8.0_162/jre/classes
Three actual combat
1 code
Import java.util.*;import java.net.*;import java.io.*;public class ClassLoaderPropTest {public static void main (String [] args) throws IOException {/ / get system class loader ClassLoader systemLoader = ClassLoader.getSystemClassLoader (); System.out.println ("system class loader:" + systemLoader) / * get the loading path of the system classloader-- usually specified by the CLASSPATH environment variable. If the operating system does not specify the CLASSPATH environment variable, the default is the current path as the system classloader load path * / Enumeration em1 = systemLoader.getResources ("); while (em1.hasMoreElements ()) {System.out.println (em1.nextElement () } / / get the parent class loader of the system class loader: get the extension class loader ClassLoader extensionLader = systemLoader.getParent (); System.out.println ("extension class loader:" + extensionLader); System.out.println ("load path of the extension class loader:" + System.getProperty ("java.ext.dirs")); System.out.println ("parent of the extension class loader:" + extensionLader.getParent ());}}
2 run
System classloader: sun.misc.Launcher$AppClassLoader@18b4aac2file:/E:/Java/IDEA_Java/out/production/IDEA_Java/ extended classloader: loading path of sun.misc.Launcher$ExtClassLoader@14ae5a5 extended classloader: d:\ Program\ Java\ jdk1.8.0_162\ jre\ lib\ ext;C:\ WINDOWS\ Sun\ Java\ lib\ ext extension classloader parent: null
Thank you for reading, the above is the content of "how to understand Java class loader and class loading mechanism". After the study of this article, I believe you have a deeper understanding of how to understand Java class loader and class loading mechanism. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.