In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "the process of initializing the servlet container after tomcat parses server.xml". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Learning background
After configuring server.xml, tomcat parses server.xml and initializes the servlet container. We learned the startup process of tomcat earlier:
Https://www.lixiang.red/articles/2019/08/07/1565188609044.html
Start method of Catalina
Following in yesterday's footsteps, after the init of Bootstrap, the start method of Bootstrap is called
Public void start () throws Exception {if (catalinaDaemon==null) {init ();} / / use reflection to call Catalina's start method Method method = catalinaDaemon.getClass (). GetMethod ("start", (Class []) null); method.invoke (catalinaDaemon, (Object []) null);}
As shown above: reflect again to call the start method of Catalina.java
At the beginning of the method, the load method is called to load the
If (getServer () = = null) {load ();} load initialization Digester related information
First, set some runtime properties in initNaming and insert the knowledge points of ENV and Property.
ENV and Propertypublic class EnvStudy {public static void main (String [] args) {Map getenv = System.getenv (); System.out.println (getenv); Properties properties = System.getProperties (); System.out.println (properties);}}
ENV is the environment variable of the computer
Properties are some of the properties of the program at run time
Initialize digester / / Before digester-it may be needed initNaming ()
/ / Create and execute our Digester / / configure the format of server.xml and the parsing rule Digester digester = createStartDigester () in createStartDigester
The code section of createStartDigester is as follows:
By comparing the previous load method, we can see two timing methods
/ / this method is specially used for timing, and its time is not related to real life time, long T1 = System.nanoTime (); / / this method is related to the operating system and corresponds to our real life time long t1=System.currentTimeMillis ()
By looking for familiar elements, we find that digester and server.xml correspond one to one.
Digester.addObjectCreate ("Server", "org.apache.catalina.core.StandardServer", "className")
What the above method represents is:
When matching to the Server node, take className to create the Object, and if the set className is empty, use StandardServer to create the Object
Stack structure of digester-top stack GlobalNamingResources-Server-Catalina-digester.addSetNext ("Server/GlobalNamingResources", "setGlobalNamingResources", "org.apache.catalina.deploy.NamingResourcesImpl")
Find the element Server at the top of the secondary stack, call its setGlobalNamingResources method, and pass the top element GlobalNamingResources as a parameter to the above method
Start the Servlet container
After a series of inputstream null judgments, begin to enter the real start-up process.
/ / use the digester rules defined above to parse server.xml inputSource.setByteStream (inputStream), digester.push (this), digester.parse (inputSource)
This is the end of the content of "tomcat initializes the servlet container after parsing server.xml". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.