What is the parent delegation mechanism

Parental delegation mechanism

The Java virtual machine uses the on-demand loading method for the class file, which means that the class file needs to be used to load the class file into the memory to generate the class object. And when the class file of a certain class is loaded, the parental delegation mode adopted by the Java virtual machine, that is, the request is handed over to the parent class for processing, which is a task delegation mode.

working principle

1) If a class loader receives a class loading request, it does not load it first, but delegates the request to the loader of the parent class to execute;

2) If the parent class loader still has its parent class loader, it will further delegate upwards, recursively, and the request will eventually reach the top-level startup class loader.

3) If the parent class loading can complete the loading task, it returns success. If the parent class loader cannot complete the loading task, the child loader will try to load it by itself. This is the parent delegation mode.

 

 

image.png

Advantage

Avoid repeated loading of classes

Protect the security of the program and prevent the core API from being tampered with at will

Custom class: java.lang.String...

Guess you like

Origin blog.csdn.net/yyp0304Devin/article/details/114240035