In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
The main content of this article is to explain "what is the method of loading Class Loader classes in Tomcat". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the method of loading classes in Tomcat's Class Loader?"
From our well-known Java to Groovy,Jython, Scala these new young people, the success of these languages, in addition to the rich features of the language, but also can not be separated from the powerful JVM.
It is because of standing on the shoulders of JVM that the new youth can see further.
Although it is possible to run these young people on JVM, there are still principles. After all, the first letter of JVM is J.
The principle mentioned here, or the new youth can run on the stage of JVM, is that after they are written in their own language syntax, the content they generate is class files. Yeah, that's the one with Java.
The same class as class. Each language uses its own compiler to generate class files according to the specification.
Are you invited by XX to compare these languages?
Of course not.
Let's take a look at the stages and ways of operating class, and who moved your "class" when.
Remember when I first learned Java, I typed javac HelloWorld.java confidently on the command line? When running the program, I look at the output "Hello World" and feel that the language has been uploaded.
It's all in your head, and you can change the world.
Javac here makes class. He is not a porter for class.
After commonly used IDE, after writing the code, the process of generating class is hidden as you save or run Main Class, and it is not even clear who compiled it.
Even after using Maven or Gradle, I double-click 666 in IDE every time and run it directly with the packed package. The compilation process, and even the packaged product, becomes a negligible step.
But then again, class plays a vital role in JVM. After JVM loads "class", it generates the corresponding "Class" object (note that C capitalizes), which in turn generates each "object" you face.
Therefore, there are many tools and frameworks that work on class to achieve some specific functions by manipulating the content of class. such as
Both Hibernate and OpenJPA modify Domain Entity class through compilation or runtime enhancements.
The famous Spring, in addition to dynamic proxy functions such as Cglib to implement AOP, also provides the function of LTW (Load Time Weave), which is enhanced when loading class.
On the other hand, transform a class, and the entry is in Java's Instrumentation. We know that this is the core of the Java agent implementation. Whether in the way of javaagent before running
Specify, or reconnect through the Attach mechanism at run time, you will get an instance of Instrumentation. With it, you can perform an addTransformer operation
"that's right, it's not adding" Transformers ", it's a converter that adds classes, and the classes are changed through transformer.
For the LTW here, if you run in a container like Tomcat, because the class is loaded by the container's ClassLoader, you will need container support.
In Tomcat 8.x, InstrumentableClassLoader has been added to instrument the class when the class is loaded. The classLoader needs to add a transformer
Used to transform subsequent loaded class.
Here is what the ClassLoader of the concrete Tomcat does when it loads the class:
When Tomcat needs to load class after addTransformer, if it is loaded in Singapore, it will go down and perform the operation according to transformer.
Iterator i$ = this.transformers.iterator (); / / here is the added converter
While (i$.hasNext ()) {
ClassFileTransformer transformer = (ClassFileTransformer) i$.next ()
Try {
Byte [] transformed = transformer.transform (this, internalName, (Class) null, (ProtectionDomain) null, binaryContent)
If (transformed! = null) {
BinaryContent = transformed
}
}
}
Try {
/ / when the class is created here, the converted binary content is used.
Clazz = this.defineClass (name, binaryContent, 0, binaryContent.length, new CodeSource (codeBase, certificates))
} catch (UnsupportedClassVersionError var17) {}
In addition, we can also modify the definition of Class at run time, add or change methods, etc. We can rely on the Attach mechanism of JVM to obtain the Instrument and then perform the reDefine of class, which we described in the previous article:
Class loader and hot replacement of classes (Hotswap)
Therefore, when build time or runtime, the class file or loaded binary content will be modified, and even at run time will be redefined to generate a new Class. So this is why Applet that can be run in browsers needs to be run in a sandbox to keep it safe.
If you encounter strange behavior while the application is running, which is inconsistent with the source code you see, don't be surprised, class may have been modified. At this point, a weapon we introduced earlier came in handy:
SA can display the class structure that you are confused about, or dump to observe it carefully locally.
At this point, I believe that you have a deeper understanding of "what is the method of loading classes in Tomcat's Class Loader". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.