Java's class loading mechanism

xiaoxiao2021-03-06  14

Java has three types of loaders, class path loaders (also called system class loaders), extended class loaders, and boot class loaders.

There are three rules on the product:

1, consistency

Once the class is loaded, there is always a memory that is retracted in memory. Once the class has been loaded, the same class is loaded from the same class loader, and the loaded thunder must be returned. The class loader only retains the HashMap, or other data structure that has been loaded, and queries the structure before trying to load the class again.

2. Entrusted rules

The class loader always queries the parent class loader before loading the class.

3, visibility

Classs can only see other classes that are delegated to their class loaders.

When the Java program takes a delegate, when you call a class, you will first be delegated to the extended class loader by the current classpath loader, and the extended class loader is delegated to the boot-loader, so that the loaded class can be guaranteed. Consistency. Class path loaders and extended class loaders are subclasses of UrlclassLoader.

To Be Continue ...

转载请注明原文地址:https://www.9cbs.com/read-46957.html

New Post(0)