参考来自Tomcat自带doc.
Tomcat 5 Startup Sequence
Sequence 1. Start from Command Line
Class: org.apache.catalina.startup.Bootstrap
What it does:
a) Set up classloaders
commonLoader (common)-> System Loader
sharedLoader (shared)-> commonLoader -> System Loader
catalinaLoader(server) -> commonLoader -> System Loader
b) Load startup class (reflection)
org.apache.catalina.startup.Catalina
setParentClassloader -> sharedLoader
Thread.contextClassloader -> catalinaLoader
c) Bootstrap.daemon.init() complete
Sequence 2. Process command line argument (start, startd, stop, stopd)
Class: org.apache.catalina.startup.Bootstrap (assume command->start)
What it does:
a) Catalina.setAwait(true);
b) Catalina.load()
b1) initDirs() -> set properties like
catalina.home
catalina.base == catalina.home(most cases)
b2) initNaming
setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
org.apache.naming.java.javaURLContextFactory ->default)
b3) createStartDigester()
Configures a digester for the main server.xml elements like
org.apache.catalina.core.StandardServer (can change of course :)
org.apache.catalina.deploy.NamingResources
Stores naming resources in the J2EE JNDI tree
org.apache.catalina.LifecycleListener
implements events for start/stop of major components
org.apache.catalina.core.StandardService
The single entry for a set of connectors,
so that a container can listen to multiple connectors
ie, single entry
org.apache.coyote.tomcat5.CoyoteConnector
Connectors to listen for incoming requests only
It also adds the following rulesets to the digester
NamingRuleSet
EngineRuleSet
HostRuleSet
ContextRuleSet
b4) Load the server.xml and parse it using the digester
Parsing the server.xml using the digester is an automatic
XML-object mapping tool, that will create the objects defined in server.xml
Startup of the actual container has not started yet.
b5) Assigns System.out and System.err to the SystemLogHandler class
b6) Calls intialize on all components, this makes each object register itself with the
JMX agent.
During the process call the Connectors also initialize the adapters.
The adapters are the components that do the request pre-processing.
Typical adapters are HTTP1.1 (default if no protocol is specified,
org.apache.coyote.http11.Http11Protocol)
AJP1.3 for mod_jk etc.
c) Catalina.start()
c1) Starts the NamingContext and binds all JNDI references into it
c2) Starts the services under <Server> which are:
StandardService -> starts Engine (ContainerBase ->Logger,Loader,Realm,Cluster etc)
c3) StandardHost (started by the service)
Configures a ErrorReportValvem to do proper HTML output for different HTTP
errors codes
Starts the Valves in the pipeline (at least the ErrorReportValve)
Configures the StandardHostValve,
this valves ties the Webapp Class loader to the thread context
it also finds the session for the request
and invokes the context pipeline
Starts the HostConfig component
This component deploys all the webapps
(webapps & conf/Catalina/localhost/*.xml)
Webapps are installed using the deployer (StandardHostDeployer)
The deployer will create a Digester for your context, this digester
will then invoke ContextConfig.start()
The ContextConfig.start() will process the default web.xml (conf/web.xml)
and then process the applications web.xml (WEB-INF/web.xml)
c4) During the lifetime of the container (StandardEngine) there is a background thread that
keeps checking if the context has changed. If a context changes (timestamp of war file,
context xml file, web.xml) then a reload is issued (stop/remove/deploy/start)
d) Tomcat receives a request on an HTTP port
d1) The request is received by a separate thread which is waiting in the PoolTcpEndPoint
class. It is waiting for a request in a regular ServerSocket.accept() method.
When a request is received, this thread wakes up.
d2) The PoolTcpEndPoint assigns the a TcpConnection to handle the request.
It also supplies a JMX object name to the catalina container (not used I believe)
d3) The processor to handle the request in this case is Coyote Http11Processor,
and the process method is invoked.
This same processor is also continuing to check the input stream of the socket
until the keep alive point is reached or the connection is disconnected.
d4) The HTTP request is parsed using an internal buffer class (Coyote Http11 Internal Buffer)
The buffer class parses the request line, the headers, etc and store the result in a
Coyote request (not an HTTP request) This request contains all the HTTP info, such
as servername, port, scheme, etc.
d5) The processor contains a reference to an Adapter, in this case it is the
Coyote Tomcat 5 Adapter. Once the request has been parsed, the Http11 processor
invokes service() on the adapter. In the service method, the Request contains a
CoyoteRequest and CoyoteRespons (null for the first time)
The CoyoteRequest(Response) implements HttpRequest(Response) and HttpServletRequest(Response)
The adapter parses and associates everything with the request, cookies, the context through a
Mapper, etc
d6) When the parsing is finished, the CoyoteAdapter invokes its container (StandardEngine)
and invokes the invoke(request,response) method.
This initiates the HTTP request into the Catalina container starting at the engine level
d7) The StandardEngine.invoke() simply invokes the container pipeline.invoke()
d8) By default the engine only has one valve the StandardEngineValve, this valve simply
invokes the invoke() method on the Host pipeline (StandardHost.getPipeLine())
d9) the StandardHost has two valves by default, the StandardHostValve and the ErrorReportValve
d10) The standard host valve associates the correct class loader with the current thread
It also retrives the Manager and the session associated with the request (if there is one)
If there is a session access() is called to keep the session alive
d11) After that the StandardHostValve invokes the pipeline on the context associated
with the request.
d12) The first valve that gets invoked by the Context pipeline is the FormAuthenticator
valve. Then the StandardContextValve gets invoke.
The StandardContextValve invokes any context listeners associated with the context.
Next it invokes the pipeline on the Wrapper component (StandardWrapperValve)
d13) During the invokation of the StandardWrapperValve, the JSP wrapper (Jasper) gets invoked
This results in the actual compilation of the JSP.
And then invokes the actual servlet.
e) Invokation of the servlet class
分享到:
相关推荐
以下是如何将Tomcat的`startup.bat`脚本转换为系统服务的详细步骤: 1. 首先,确保你的系统环境配置正确。在安装Tomcat后,你需要设置几个环境变量: - `JAVA_HOME`: 指向JRE(Java Runtime Environment)的安装...
如果不想以服务方式运行,但仍然想在命令行启动Tomcat而不显示窗口,可以在启动命令后添加`-startup`参数,例如:`startup.bat -startup`。这将在后台启动Tomcat,但仅适用于手动启动,不适合自动启动或远程操作。 ...
### Tomcat5启动流程与配置详解 #### 一、Tomcat5.0目录结构 Tomcat作为一款广泛使用的开源Web服务器软件,其5.0版本的目录结构清晰且功能明确,便于用户理解和维护。以下是对Tomcat5.0各个目录的具体介绍: 1. *...
使用Tomcat+Geoserver发布地图数据使用的工具包。将Geoserver解压后文件geoserver.war再次解压,然后放入Tomcat目录webapps目录下。最后运行Tomcat的bin目录下startup.bat启动Tomcat即可
1. **JAVA_HOME环境变量未正确设置**:这是最常见的导致Tomcat启动失败的原因之一。如果JAVA_HOME环境变量没有被正确地定义,或者其值指向了一个不存在或不合适的路径(例如指向了JRE而非JDK),那么Tomcat将无法...
通过这个startup.bat文件,我们可以了解Tomcat服务器的启动过程和环境变量的设置方式,从而更好地掌握Tomcat服务器的配置和使用。 此外,我们也可以学习到批处理文件的编写技巧和DOS命令的使用方法,从而提高我们的...
【描述】:Tomcat启动管理工具涵盖了启动、停止、监控以及配置Tomcat服务器的过程。这些工具可以帮助开发者有效地管理他们的应用服务,确保系统稳定运行,并在必要时进行故障排查。 【标签】: 1. Tomcat:Apache ...
这个过程对于软件实施工程师来说非常重要,因为它可以简化维护工作,避免每次系统重启后手动启动Tomcat。以下是如何在CentOS 7上设置Tomcat 8开机启动的详细步骤: 1. **配置Tomcat环境变量**: 首先,我们需要在...
3. **启动Tomcat**:进入解压后的bin目录,运行`startup.sh`脚本来启动Tomcat服务。 ``` cd apache-tomcat-8.5.47/bin/ ./startup.sh ``` 4. **验证Tomcat状态**:通过`ps`命令检查Tomcat是否已经成功启动。...
注意:在访问项目之前,需要先手动启动 Tomcat 的 startup.bat,以确保项目的端口正确以及项目是否报错。 本文详细介绍了如何在 Server 2008 环境下配置 Tomcat 的后台启动,以便在系统启动时自动启动 Tomcat 服务...
【标题】:Tomcat启动顺序 【描述】:Tomcat作为Apache软件基金会的开源Java Servlet容器,其启动过程是理解其工作原理的关键部分。Tomcat的启动顺序涉及到多个层次的加载,从Bootstrap类开始,逐步加载系统配置、...
### CentOS 设置 Tomcat 开机自启动 #### 一、前言 在生产环境中,为了确保应用服务器能够稳定运行,我们通常需要配置应用服务器在系统重启后自动启动。本篇文章将详细介绍如何在CentOS环境下配置Tomcat服务器实现...
“Tomcat一闪”现象的主要原因在于`startup.bat`脚本未能正确执行,或者Java虚拟机(JVM)未能成功启动。具体来说,有以下几个可能的原因: 1. **环境变量配置错误**:`JAVA_HOME`等关键环境变量未正确设置或路径...
Tomcat开机自启动是指在 Linux 操作系统中,使 Tomcat 服务器在系统启动时自动启动的过程。下面将详细介绍 Tomcat 开机自启动的步骤和相关知识点。 一、基本概念 在开始之前,需要了解一些基本概念: * Tomcat:...
"Tomcat启动停止脚本"提供了这样的便利,使得操作过程自动化,特别是当需要将这些操作集成到服务器的计划任务中时。 一、Tomcat启动脚本 启动脚本通常名为`startup.sh`(在Unix/Linux环境)或`startup.bat`(在...
1. `bin`:包含启动、停止和管理Tomcat的脚本,如`startup.sh`和`shutdown.sh`(Unix/Linux)或`startup.bat`和`shutdown.bat`(Windows)。 2. `conf`:存放服务器配置文件,如`server.xml`(定义服务器配置)、`...
进入该目录后,运行`./startup.sh`即可启动Tomcat服务。如果是使用非交互式shell或远程登录环境,建议使用`sh startup.sh`命令。 ```bash cd /usr/local/tomcat/bin ./startup.sh ``` - **使用自定义脚本**:...
6. **命令行接口(CLI)**:Tomcat提供了命令行工具,如`startup.sh`和`shutdown.sh`(在Unix/Linux系统中)或`startup.bat`和`shutdown.bat`(在Windows中),可以用于启动和停止服务。在C#程序中,可以使用`Process....
以下是对Tomcat启动流程的详细解析: 1. **初始化环境** - Tomcat启动前,首先会检查并配置系统环境,包括JDK版本、JAVA_HOME、CATALINA_HOME等环境变量。 - 阅读`conf/server.xml`配置文件,这是Tomcat的核心...
问题:使用免安装的tomcat双击startup.bat后,启动窗口一闪而过,而且tomcat服务未启动。 原因:在启动tomcat是需要读取环境变量和配置信息,缺少了这些信息,就不能登记环境变量,导致了tomcat的闪退。 解决办法: ...