tomcat启动(三)Catalina简要分析
上篇解析Bootstrap到
daemon.setAwait(true);
daemon.load(args);
daemon.start();
这三个方法实际是反射调用org.apache.catalina.startup.Catalina类的方法
对Catalina类有一段解释
这个google翻译真强
Startup/Shutdown shell program for Catalina. The following command line options
are recognized:
•-config {pathname} - Set the pathname of the configuration file to be processed.
If a relative path is specified, it will be interpreted as relative to the directory
pathname specified by the "catalina.base" system property. [conf/server.xml]
•-help - Display usage information.
•-nonaming - Disable naming support.
•configtest - Try to test the config
•start - Start an instance of Catalina.
•stop - Stop the currently running instance of Catalina.
Catalina的启动/关闭shell程序。可以识别以下命令行选项:
•-config {pathname} - 设置要处理的配置文件的路径名。如果指定了相对路径,
它将被解释为相对于由“catalina.base”系统属性指定的目录路径名。
[conf / server.xml]
•-help - 显示使用信息。
•-nonaming - 禁用命名支持。
•configtest - 尝试测试配置
•start - 启动Catalina的实例。
•stop - 停止当前正在运行的Catalina实例。
setAwait load() ,start()方法
setAwait() 略过。。。这个方法设置一个boolean值的await也不知道干吗了
load()方法里
几个重要的类和方法在后面会详细解释
createStartDigester()
Digester.java
InputSource
/**
* Start a new server instance.
*/
public void load() { long t1 = System.nanoTime(); initDirs();这里主要是获取java.io.tmpdir操作系统缓存临时目录 // Before digester - it may be needed
initNaming();初始化命名服务的基本配置 // Create and execute our Digester下面会详细探索这个方法作用
Digester digester = createStartDigester();Digester类,主要用于处理xml配置文件(如conf/server.xml),根据xml的结构转生成对应的java对象 InputSource inputSource = null;
InputStream inputStream = null;
File file = null;
try {
try {// 配置文件,由命令行参数-config指定,否则取默认值conf/server.xml
file = configFile();
inputStream = new FileInputStream(file);
inputSource = new InputSource(file.toURI().toURL().toString());
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("catalina.configFail", file), e);
}
}
。中间省略一大堆前置条件。就是判断inputStream和inputSource为空的操作
。
。
try {
inputSource.setByteStream(inputStream);
digester.push(this);
//解析server.xml里的Server并复制给Catalina类的server属性,而Server只有一个标准实现StandardServer,所以后面的getServer()即返回StandardServer
digester.parse(inputSource);
} catch (SAXParseException spe) {
log.warn("Catalina.start using " + getConfigFile() + ": " +
spe.getMessage());
return;
} catch (Exception e) {
log.warn("Catalina.start using " + getConfigFile() + ": " , e);
return;
}
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// Ignore
}
}
}
//是代表一个servlet容器AServerelement represents the entire Catalina servlet container
getServer().setCatalina(this);为server设置外置Catalina组件component,这里设置当前Catalina对象为外置组件
getServer().setCatalinaHome(Bootstrap.getCatalinaHomeFile());
getServer().setCatalinaBase(Bootstrap.getCatalinaBaseFile()); // Stream redirection流的重定向,将out和err进行包装
initStreams();//Replace System.out and System.err with a custom PrintStream // Start the new server
try {
//Prepare the component for starting.
//This method should perform any initialization required post object creation.
//The followingLifecycleEvents will be fired in the following order:
getServer().init();
} catch (LifecycleException e) {
if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE")) {
throw new java.lang.Error(e);
} else {
log.error("Catalina.start", e);
}
} long t2 = System.nanoTime();
if(log.isInfoEnabled()) {
log.info("Initialization processed in " + ((t2 - t1) / 1000000) + " ms");
}
}
Catalina 的start()方法
判断server是否为空,空就调用load()加载组件,不为空就调用server.start()方法
这个方法最终执行了server的start
在启动后会注册Register shutdown hook注册关闭钩子
/**Prepare for the beginning of active use of the public methods other than property getters/setters
and life cycle methods of this component.
This method should be called before any of the public methods other than property getters/setters
and life cycle methods of this component are utilized.
The following LifecycleEvents will be fired in the following order:
1.BEFORE_START_EVENT: At the beginning of the method. It is as this point the state transitions to LifecycleState.STARTING_PREP.
2.START_EVENT: During the method once it is safe to call start() for any child components.
It is at this point that the state transitions to LifecycleState.
STARTING and that the public methods other than property getters/setters and life cycle methods may be used.
3.AFTER_START_EVENT: At the end of the method, immediately before it returns. It is at this point that the state
transitions to LifecycleState.STARTED.
Throws:LifecycleException - if this component detects a fatal error that prevents this component from being used
*/
准备开始这个active ,
这个start方法是所有组件的公共方法
tomcat中所有的server组件都实现了org.apache.catalina.Lifecycle这个接口。
对于Lifecycle接口的解释Common interface for component life cycle methods管理组件生命周期的公共接口
start方法是定义在Lifecycle接口中 getServer().start(); // Register shutdown hook
if (useShutdownHook) {
if (shutdownHook == null) {
shutdownHook = new CatalinaShutdownHook();
}
Runtime.getRuntime().addShutdownHook(shutdownHook); // If JULI is being used, disable JULI's shutdown hook since
// shutdown hooks run in parallel and log messages may be lost
// if JULI's hook completes before the CatalinaShutdownHook()
LogManager logManager = LogManager.getLogManager();
if (logManager instanceof ClassLoaderLogManager) {
((ClassLoaderLogManager) logManager).setUseShutdownHook(
false);
}
}
进入详细探索。分割条出来吧O(>人<)O
太长了。下一章吧
神级博客:
holly2k大神关于tomcat解析的目录http://blog.csdn.net/holly2k/article/category/1348477
tomcat源码分析-Bootstrap操作Catalina
tomcat启动(三)Catalina简要分析的更多相关文章
- tomcat启动(三)Catalina分析-load方法分析
load()方法按从上到下顺序分析(主要分析本人所没学过的知识点,其它略过...). Digester类作用 使用sax技术对xml进行解析 未开始解析时Digester.push(this)这个用来 ...
- [Tomcat 源码分析系列] (二) : Tomcat 启动脚本-catalina.bat
概述 Tomcat 的三个最重要的启动脚本: startup.bat catalina.bat setclasspath.bat 上一篇咱们分析了 startup.bat 脚本 这一篇咱们来分析 ca ...
- tomcat启动(六)Catalina分析-StandardServer.start()
从链接 Tomcat中组件的生命周期管理公共接口Lifecycle 可以知道调用的是StandardServer.startInternal() @Override protected void st ...
- tomcat启动(五)Catalina分析-service.init
上篇写到StandardService.init() 这个方法做什么呢?一起来看看. 这个类也是实现了Lifecycle 如图.这个图中i表示Interface接口.如Lifecycle,Contai ...
- tomcat启动(四)Catalina分析-server的init()方法
上一回load()方法解析讲到xml解析完成. load()内部接下来会获取server getServer().setCatalina(this); 这个server从createStartDige ...
- tomcat启动批处理——catalina.bat
这个批处理才是tomcat服务器启动跟关闭的核心脚本.其中包括....(各种变量),此节将详细讲解这个批处理的逻辑. 先看看第一部分脚本: ****************************** ...
- Tomcat启动脚本catalina.sh
1 - 概述脚本catalina.sh用于启动和关闭tomcat服务器,是最关键的脚本另外的脚本startup.sh和shutdown.sh都是使用不同的参数调用了该脚本该脚本的使用方法如下(引自该脚 ...
- tomcat启动(Ⅶ)请求处理--Processor.process(SocketWrapper<S> socketWrapper)
tomcat启动(六)Catalina分析-StandardServer.start() 上一篇分析到:Http11NioProcessor.process(SocketWrapper<S> ...
- Tomcat源码分析三:Tomcat启动加载过程(一)的源码解析
Tomcat启动加载过程(一)的源码解析 今天,我将分享用源码的方式讲解Tomcat启动的加载过程,关于Tomcat的架构请参阅<Tomcat源码分析二:先看看Tomcat的整体架构>一文 ...
随机推荐
- [jquery-delegate] iphone_4s _iphone _5c_中不兼容jQuery delegate 事件(does not wok)
1. jQuery .on() and .delegate() doesn't work on iPad http://stackoverflow.com/questions/10165141/jqu ...
- Android蓝牙联机Demo解析
写在前面: 手游的双人对战实现方式有很多,比如: 联网对战(需要一个服务器负责转发客户端请求,各种大型手游的做法) 分屏对战(手机上下分屏,典型的例子就是切水果的双人对战) 蓝牙联机对战(通过蓝牙联机 ...
- [ASP.NET]大文件无法上传排查经验分享
最近我们标桥下载模块,在经过正常更新后,发现软件包无法上传. 临时解决方案 因为问题结点在于文件无法上传到服务器,所以我们临时手动将文件丢到服务器,通过测试服务器将数据造出来,然后再更新到正式数据库, ...
- ODP.NET 之 ExecuteNoQuery 执行 Merge into 返回值
当执行Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery时,如果sql语句是 merge into ...,则返回值表现不稳定, ...
- log4net 未生成log 原因分析
本文假定你对log4net的配置以及在代码中的使用都非常熟悉,但就是没有按预想的生成log文件,正当你抓耳挠腮之时,那以下原因很可能是你解决问题的办法: 1.log4net.dll是否生成到程序运行目 ...
- Unreal Open Day游记
前几天去参加了Unreal Open Day,周四早上从北京出发,坐地铁跟徐导,呵呵,simon他们汇合后,打车去了北京南站.一路上有小雨,不禁让人多少有点担心堵车,好在一路顺利.由于还没有一台较牛的 ...
- super函数的用法
1.创建一个类. # .创建一个类 class Bird: def __init__(self): self.hungry =True def eat(self): if self.hungry: p ...
- Python廖雪峰学习笔记——单元测试
定义:对一个模块.一个类.一个函数进行进行正确性检验的测试性工作.当我们对函数或者模块等进行修改时,单元测试就显得尤为重要. 单元测试 = 测试用例(用来测试的数据)+测试模块
- (进阶篇)PHP(thinkphp5框架)实现用户注册后邮箱验证,激活帐号
本文将结合实例,讲解如何使用thinkphp5+Mysql完成注册帐号.发送激活邮件.验证激活帐号.处理URL链接过期的功能. 业务流程 1.用户提交注册信息. 2.写入数据库,此时帐号状态未激活. ...
- 操作系统(Operating System,OS)
操作系统(Operating System,OS) 是配置在计算机硬件上的第一层软件,是对计算机硬件系统的首次扩充,是一个计算机系统最基础,也是最重要的系统软件. 操作系统的作用 1 实现对计算机资源 ...