下面是
● standardEngine的启动
(1) 首先是StandardEngine.start()被调用
public void start() throws LifecycleException {
// Standard container startup
//进行logger,manager,cluster,realm,resource的启动
super.start();
}
(2) super.start()--->org.apache.catalina.core.ContainerBase#start()
public synchronized void start() throws LifecycleException {
//(省略) server.xml中配置应用组件的启动
//StandardHost容器的启动,
Container children[] = findChildren();
for (int i = 0; i < children.length; i++) {
if (children[i] instanceof Lifecycle)
((Lifecycle) children[i]).start();
}
//StandardPipeline的启动(容器与容器间的管道)
if (pipeline instanceof Lifecycle)
((Lifecycle) pipeline).start();
}
(3) StandardHost.start()被调用
public synchronized void start() throws LifecycleException {
//返回到以上的containerBase#start执行pipeline
super.start();
}
(4) StandardPipeline#start
public synchronized void start() throws LifecycleException {
// 将会调用HostConfig#start方法
lifecycle.fireLifecycleEvent(START_EVENT, null);
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
}
(5) HostConfig#start
public void start() {
//部暑webapps
deployApps();
}
(6) HostConfig#deployApps
protected void deployApps() {
File appBase = appBase();
File configBase = configBase();
// Deploy XML descriptors from configBase
deployDescriptors(configBase, configBase.list());
// Deploy WARs, and loop if additional descriptors are found
deployWARs(appBase, appBase.list());
// Deploy expanded folders
deployDirectories(appBase, appBase.list());
}
(7) deployWARs
protected void deployWARs(File appBase, String[] files) {
……
deployWAR(contextPath, dir, file);
}
(8) deployWAR
protected void deployWAR(String contextPath, File war, String file) {
if (context instanceof Lifecycle) {
// (省略)
Class clazz = Class.forName(host.getConfigClass());
LifecycleListener listener =
(LifecycleListener) clazz.newInstance();
((Lifecycle) context).addLifecycleListener(listener);
}
context.setPath(contextPath);
context.setDocBase(file);
//以下这一步跟进去,,StandardContext的启动
host.addChild(context);
}
(9) StandardContext#start
在Context的启动过程中,主要完成了以下任务。
----------------------------------------------------------------------------------------------------------------------
a) 设置web app的具体目录webappResources。
b) postWorkDirectory (),创建临时文件目录。Tomcat下面有一个work目录,用来存放临时文件。
c) 触发START_EVENT事件监听,在这个事件监听里面会启动ContextConfig的start()事件,ContextConfig是用来配置web.xml的。
d) 为context创建welcome files,通常是这三个启动文件:index.html、index.htm、index.jsp
e) 配置filter
f) 启动带有<load-on-startup>的Servlet。
g) 注册JMX。
----------------------------------------------------------------------------------------------------------------------
至此,Container启动完毕,下面是connector的启动。
● connector的启动
(1) org.apache.catalina.connector.Connector.start()
public void start() throws LifecycleException {
// Http11Protocol的启动
protocolHandler.start();
}
(2) Http11Protocol#start
public void start() throws Exception {
try {
//到了终点的启动
endpoint.start();
} catch (Exception ex) {
log.error(sm.getString("http11protocol.endpoint.starterror"), ex);
throw ex;
}
(3) JIoEndPoint#start
public void start()
throws Exception {
for (int i = 0; i < acceptorThreadCount; i++) {
//这里的acceptor是一个线程,里面是一个serversocket的启动
Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i);
acceptorThread.setPriority(threadPriority);
acceptorThread.setDaemon(daemon);
acceptorThread.start();
}
}
(4) Acceptor#run
public void run() {
// Accept the next incoming connection from the server socket
try {
//这里进行了accept(),等待客户端消息,进行接收
Socket socket = serverSocketFactory.acceptSocket(serverSocket);
serverSocketFactory.initSocket(socket);
// Hand this socket off to an appropriate processor
if (!processSocket(socket)) {
// Close socket right away
try {
socket.close();
} catch (IOException e) {
// Ignore
}
}
}catch ( IOException x ) {
if ( running ) log.error(sm.getString("endpoint.accept.fail"), x);
} catch (Throwable t) {
log.error(sm.getString("endpoint.accept.fail"), t);
}
}
至此Connector.start方法调用完毕。整个server启动完毕。
分享到:
相关推荐
tomcat-redis-session-manager源码
开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-windows-x86开发工具 apache-tomcat-8.0.41-...
apache-tomcat-8.5.20.tar.gz源码包和context.xml文件,这套配置是我自己亲测可用的。。另外我用的redis4这个版本。注意:如果你使用的TOMCAT其他版本。例如tomcat6或者7这套JAR包可能不可用,tomcat8.0没有测试。...
Tomcat8亲测可用 tomcat-redis-session-manager的jar包 修改了tomcat-redis-session-manager源码进行的编译生成的jar包
7.0.59版本,直接去关联这个压缩包即可.如果版本不对http://archive.apache.org/dist/tomcat/去官网直接下也可以.
apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-tomcat-9.0.45-windows-x64apache-...
apache-tomcat-6.0.53-src,apache tomcat 6.0.53的源码。 压缩包文件清单: apache-tomcat-6.0.53-src.tar.gz apache-tomcat-6.0.53-src.tar.gz.asc apache-tomcat-6.0.53-src.tar.gz.md5 apache-tomcat-6.0.53-...
这个是一个Tomcat源码,喜欢代码分析的课可以参考这个源码进行学习,网上有很多的源码导入方式,可以参考网上的源码导入方式来进行Tomcat源码学习
因tomcat7使用redis共享session,其他的包存在问题,自己编译后处理通过。 该包是在https://github.com/jcoleman/tomcat-redis-session-manager 将源码编译后的包。
基于tomcat-redis-session-manager源码进行的编译生成的jar包,压缩包中包含Tomcat7和Tomcat8打好的jar包。
apache-tomcat-7.0.90-src源码 apache-tomcat-7.0.90-src源码
MyEclipse导入Tomcat源码.wps文档说明 apache-tomcat-6.0.37-src.zip源码
tomcat8下 tomcat-redis-session-manager , github上有源码,其他版本都有打好的jar包,tomcat 8 下没有,下载源码生成了一个。
`tar -zxvf apache-tomcat-8.0.21.tar.gz -C /usr/local/tomcat` 四、配置环境变量 为了使Tomcat能够正确工作,需要配置环境变量。使用以下命令编辑/etc/profile文件: `export JAVA_HOME=/usr/java/jdk1.7.0_80`...
apache-tomcat-9.0.14-src 源码 tomcat-9.0.14源码
tomcat 源码分析系列文档 http深入分析,tomcat中类的加载,tomcat的启动,tomcat的容器思想,
apache-tomcat-7.0.59-src apache-tomcat-7.0.69-src Tomcat 7.0.59,Tomcat 7.0.69 源码
tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码tomcat 源码
tomcat-connectors-1.2.32-src.tar.gz 在linux下,进行apache和tomcat整合时要用的源码安装文件
该压缩包含有apache-tomcat-7.0.62-src和apache-tomcat-6.0.39-src的源码。