In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "the startup process of tomcat". In the operation of actual cases, many people will encounter such a dilemma. Next, 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
In the first two articles, we talked about the source structure of tomcat
Https://www.lixiang.red/articles/2019/08/04/1564907616303.html
There is also the server.xml structure of tomcat.
Https://www.lixiang.red/articles/2019/08/06/1565094623138.html
Today we will continue to watch the startup process of tomcat.
Start with the known startup.bat/sh
The startup on windows is: startup.bat
The startup on linux/mac is startup.sh
Startup.sh
The point is on the last line:
# PRGDIR is the bin directory PRGDIR= `dirname "$PRG" `under the current tomcat
EXECUTABLE=catalina.sh
Execute tomcat/bin/catalina.sh start $@ to represent all the parameters, exec "$PRGDIR" / "$EXECUTABLE" start "$@" catalina.sh
We trace through the parameter start:
Here you can see how to judge the start parameters and then follow different branching logic
After a lot of judgment, when the bootable state is finally reached, the startup command is executed:
Nohup: in linux system, you can run the program in the background, and the window closure will also exist.
ENDORSED_PROP: can override some classes loaded by the jvm bootstarp class loader
Org.apache.catalina.startup.Bootstrap: this class will be executed eventually
Bootstrap
According to the above, we can find the main function of the class Bootstrap
As shown in the figure above, as long as the following steps are performed:
1. Initialize bootstrap instance
two。 Call the init method of bootstrap to deinitialize the classloader and the catalina instance
3. Call the start method of bootstrap, and then call the start method of catalina through reflection
Init ():
Public void init () throws Exception {/ / initialize classloader initClassLoaders (); / / set the current thread's classloader to catalinaLoader / / current thread: initialize the thread of Catalina, initialize the thread of the Servlet container Thread.currentThread (). SetContextClassLoader (catalinaLoader)
SecurityClassLoad.securityClassLoad (catalinaLoader)
/ / Load our startup class and call its process () method if (log.isDebugEnabled ()) {log.debug ("Loading startup class");} / find the Catalina class, and then instantiate Class startupClass = catalinaLoader.loadClass ("org.apache.catalina.startup.Catalina") with reflection; Object startupInstance = startupClass.getConstructor () .newInstance ()
/ / Set the shared extensions class loader if (log.isDebugEnabled ()) {log.debug ("Setting startup class properties");} / get the method to Catalina.setParentClassLoader String methodName = "setParentClassLoader"; Class paramTypes [] = new Class [1]; paramTypes [0] = Class.forName ("java.lang.ClassLoader"); Object paramValues [] = new Object [1] ParamValues [0] = sharedLoader; / / the parent class loader used by the Catalina instance set by reflection is sharedLoader Method method = startupInstance.getClass () .getMethod (methodName, paramTypes); method.invoke (startupInstance, paramValues)
CatalinaDaemon = startupInstance
}
Start ():
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)
} A few last words
This completes the initial initialization of tomcat from the command line to bootstrap and catalina. There is also the loading of server,service, Engine, host and other components.
This is the end of the content of the startup process of tomcat. Thank you for your 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.