Tomcat源码阅读之Engine启动过程
来源:互联网 发布:小程序 video.js 编辑:程序博客网 时间:2024/05/17 07:20
Tomcat的Start过程有两条主线,第一条启动Container组件,另一条启动Connector组件。
public void start() throws LifecycleException { 。 。 。 略 lifecycle.fireLifecycleEvent(START_EVENT, null); started = true; // Start our defined Container first //启动容器 if (container != null) { synchronized (container) { if (container instanceof Lifecycle) { ((Lifecycle) container).start(); } } } // Start our defined Connectors second //启动连接器 synchronized (connectors) { for (int i = 0; i < connectors.length; i++) { try { ((Lifecycle) connectors[i]).start(); } catch (Exception e) { log.error(sm.getString( "standardService.connector.startFailed", connectors[i]), e); } } } // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null); }
首先看看启动Container容器部分的源码。
最先启动的容器是Engine,在StandardEngine类的start方法中进行一系列的JMX服务注册之后,接着会调用父类ContainerBase的start方法。
public synchronized void start() throws LifecycleException { 略 // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null); started = true; 略 // Start our child containers, if any Container children[] = findChildren(); for (int i = 0; i < children.length; i++) { if (children[i] instanceof Lifecycle) ((Lifecycle) children[i]).start(); } // Start the Valves in our pipeline (including the basic), if any if (pipeline instanceof Lifecycle) ((Lifecycle) pipeline).start(); // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(START_EVENT, null); // Start our thread threadStart(); // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null); }
在start方法中会触发三个事件,分别是before_start,start,after_start。既然有事件产生,那么就应该有处理事件的监听器。Engine容器的监听器是EngineConfig类,EngineConfig实现了LifecycleListener接口,因此事件的处理逻辑在lifecycleEvent方法中。在EngineConfig的lifecycleEvent方法中处理事件的逻辑比较简单,只是记录一下操作日志,因此Engine容器启动产生的几个事件可以不用太关注。Engine容器启动过程中会找出它所有的Host子类,并且调用Host对应的start方法启动Host容器。除了启动Host容器,还会启动一个线程执行后台处理任务,线程的run方法中会周期性的调用processChildren方法,而processChildren方法会调用自身对象backgroundProcess方法和每个子容器的processChildren方法。在backgroundProcess方法中会检查类的时间戳,Session对象的超时时间和执行Context容器的reload等操作。而reload操作的实质是先停止其子容器,然后再启动,只不过这个操作是由程序自动发起而不是由用户产生的。
- Tomcat源码阅读之Engine启动过程
- Tomcat源码阅读之Host启动
- Tomcat源码阅读之Context启动
- Tomcat源码阅读之Connector启动
- Tomcat源码阅读之Init过程
- Tomcat源码阅读之Load过程
- Tomcat源码阅读之请求过程
- Tomcat源码阅读系列(三)启动和关闭过程
- Tomcat源码阅读之Bootstrap启动流程与classLoader设计
- 解读tomcat源码之tomcat的启动过程
- tomcat源码---启动过程分析
- Tomcat源码分析--启动过程
- Tomcat启动过程源码研究
- Tomcat源码阅读之过滤器
- tomcat源码阅读之Digester
- Tomcat连接器运行过程(源码阅读)
- [Tomcat源码]Tomcat的启动过程
- seaweedfs源码阅读4-volume启动过程
- apple pay支持的银行有哪些?如何绑定银行卡?
- 2016SCZSC Day2
- java面试题12--Integer--自动拆装箱
- 赋值运算符
- 欧拉函数
- Tomcat源码阅读之Engine启动过程
- HDU1756 Cupid's Arrow (判断点在多边形内)
- LATEX中插入VISIO制图
- 二叉树的建立学习笔记
- 基于 jQuery 的图片自动上传插件
- HDU 4027 Can you answer these queries?[区间求和+区间更新]
- 关系表达式
- Java中什么是序列化?
- Android数据存储:获取网络图片把图片保存到SD卡中并从SDk卡中读取(通过Bitmap方法)