[小析]tomcat源码


tomcat启动类Bootstrap

启动tomcat服务命令:

java -cp "%CATALINA_HOME%\bin\bootstrap.jar" org.apache.catalina.startup.Bootstrap start

Bootstrap options: start,startd,stop,stopd

注: CATALINA_HOME: tomcat安装目录


类org.apache.catalina.startup.Bootstrap用于启动tomcat

源码中此类描述:

Boostrap loader for Catalina. This application constructs a class loader for use in loading the Catalina internal classes (by accumulating all of the JAR files found in the "server" directory under "catalina.home"), and starts the regular execution of the container. The purpose of this roundabout approach is to keep the Catalina internal classes (and any other classes they depend on, such as an XML parser) out of the system class path and therefore not visible to application level classes.


其main函数描述:

Main method, used for testing only.


这只是一个引导类,真正的处理类是%CATALINA_HOME%\lib\catalina.jar类库中的org.apache.catalina.startup.Catalina类.通过直接运行org.apache.catalina.startup.Catalina start也能启动tomcat启动.


二者区别在于,Bootstrap类将相关的类库组成好了,除了bootstrap.jar外,不需要设置类路径.

而Catalina类则需要设置依赖的类路径.


----------------------------------------------------------------------------------------------

Catalina类启动服务依次调用方法main()->process()->load()->start()->

load()方法用来Load using arguments.

函数先判断%CATALINA_HOME%\conf\server.xml(Pathname to the server configuration file)的存在性,加载该配置文件;

然后,通过Service实现类(org.apache.catalina.startup.StandardService)对象实例getServer()返回一个Server实现类(org.apache.catalina.core.StandardServer)对象实例.

最后,Invoke a pre-startup initialization. This is used to allow connectors to bind to restricted ports under Unix operating environments.


相关log日志输出信息:

2011-5-14 21:12:11 org.apache.coyote.http11.Http11Protocol init

信息: Initializing Coyote HTTP/1.1 on http-8080


到此完成初始化处理:

2011-5-14 21:12:11 org.apache.catalina.startup.Catalina load

信息: Initialization processed in 1153 ms


start()方法用来Start a new server instance.

((Lifecycle) getServer()).start();

执行org.apache.catalina.core.StandardServer类中的start()方法.


----------------------------------------------------------------------------------------------

未完

猜你喜欢

转载自jarg.iteye.com/blog/1044403