`
javaboy2006
  • 浏览: 186272 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Tomcat 5 Startup Sequence

    博客分类:
  • java
阅读更多
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

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
	         


http://tomcat.apache.org/tomcat-6.0-doc/architecture/startup.html
分享到:
评论

相关推荐

    将tomcat的startup.bat改为系统服务的方法

    以下是如何将Tomcat的`startup.bat`脚本转换为系统服务的详细步骤: 1. 首先,确保你的系统环境配置正确。在安装Tomcat后,你需要设置几个环境变量: - `JAVA_HOME`: 指向JRE(Java Runtime Environment)的安装...

    tomcat之startup.bat详解.pdf

    Tomcat之startup.bat详解 Tomcat的startup.bat文件是Tomcat服务器的启动文件,位于Tomcat的bin目录下。该文件是一个批处理文件,用于设置Tomcat服务器的环境变量和启动参数。在这个文件中,我们可以看到许多批处理...

    双击startup.bat,启动不了tomcat

    ### 双击startup.bat无法启动Tomcat的问题及解决方案 #### 问题概述 用户尝试通过双击`startup.bat`脚本来启动Tomcat服务器时遇到了问题,系统提示“JAVA_HOME environment variable is not defined correctly”。...

    关于tomcat点击startup.bat后闪退问题的解决办法

    问题:使用免安装的tomcat双击startup.bat后,启动窗口一闪而过,而且tomcat服务未启动。 原因:在启动tomcat是需要读取环境变量和配置信息,缺少了这些信息,就不能登记环境变量,导致了tomcat的闪退。 解决办法: ...

    tomcat5/tomcat5.5安装包

    1. `bin`:包含启动、停止和管理Tomcat的脚本,如`startup.sh`和`shutdown.sh`(Unix/Linux)或`startup.bat`和`shutdown.bat`(Windows)。 2. `conf`:存放服务器配置文件,如`server.xml`(定义服务器配置)、`...

    Tomcat7.0+Geoserver2.14.0

    使用Tomcat+Geoserver发布地图数据使用的工具包。将Geoserver解压后文件geoserver.war再次解压,然后放入Tomcat目录webapps目录下。最后运行Tomcat的bin目录下startup.bat启动Tomcat即可

    直接双击启动tomcat中的startup.bat闪退原因及解决方法

    免安装的tomcat双击startup.bat后,启动窗口一闪而过,而且tomcat服务未启动。 原因是:在启动tomcat是,需要读取环境变量和配置信息,缺少了这些信息,就不能登记环境变量,导致了tomcat的闪退。 解决办法: 1.在已...

    tomcat startup.bat

    #include &lt;sys/ipc.h&gt; #include &lt;sys/mman.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/wait.h&gt; #include &lt;sys/stat.h&gt;

    tomcat一闪的问题—已解决

    5. **Tomcat安装目录权限问题**:如果Tomcat的安装目录没有足够的访问权限,也会影响其正常运行。 #### 三、解决方案 根据题目中提供的信息,我们可以看到一段经过修改的`startup.bat`脚本代码片段,通过这段代码...

    Tomcat压缩包,直接解压,打开bin目录的startup文件,不会乱码。

    5. `logs`目录:记录Tomcat运行时的日志信息。 6. `temp`目录:用于存放临时文件。 7. `work`目录:存放JSP编译后的类文件以及Servlet处理请求时生成的临时文件。 【启动Tomcat】 在命令行中,切换到`bin`目录下,...

    tomcat startup

    tomcat startuptomcat startuptomcat startuptomcat startup

    Tomcat 5帮助文档

    3. **启动与关闭**:使用bin目录下的startup.bat或startup.sh脚本启动Tomcat,使用shutdown.bat或shutdown.sh脚本关闭。在命令行中,也可以通过控制台输出监控Tomcat的状态。 4. **部署Web应用**:将WAR文件或整个...

    Tomcat5的目录结构

    - `startup.bat`和`startup.sh`:用于启动Tomcat服务,其中`.bat`版本适用于Windows系统,而`.sh`版本适用于Unix/Linux系统。 - `shutdown.bat`和`shutdown.sh`:用于停止正在运行中的Tomcat服务。 - 还包含其他...

    tomcat启动startup.bat一闪而过问题的解决方法【亲测有效】

    5. 故障排查:遇到Tomcat启动一闪而过的情况时,可以通过查看Tomcat日志文件获取更多信息。日志文件通常位于Tomcat安装目录的logs文件夹下。通过阅读日志文件,可以找到导致Tomcat启动失败的具体原因,并根据错误...

    命令行启动关闭tomcat而不显示cmd界面

    如果不想以服务方式运行,但仍然想在命令行启动Tomcat而不显示窗口,可以在启动命令后添加`-startup`参数,例如:`startup.bat -startup`。这将在后台启动Tomcat,但仅适用于手动启动,不适合自动启动或远程操作。 ...

    tomcat自动定时重启

    本篇文章将深入探讨如何实现"Tomcat自动定时重启"这一功能,以及提供的两个批处理文件——`Tomcat_startup.bat`和`Tomcat_shutdown.bat`的作用。 首先,`Tomcat_startup.bat`和`Tomcat_shutdown.bat`是Tomcat服务器...

    Tomcat中的startup.bat原理详细解析

    平时启TOMCAT都是鼠标双击startup.bat了,很少看过里面写的是什么,也借学习TOMCAT的机会学习一下批处理的常用命令,不求都记住,但求以后再见到批处理命令能看的懂,说的出是干什么的。本文主要给大家介绍了关于...

    Tomcat5启动流程与配置详解 .

    ### Tomcat5启动流程与配置详解 #### 一、Tomcat5.0目录结构 Tomcat作为一款广泛使用的开源Web服务器软件,其5.0版本的目录结构清晰且功能明确,便于用户理解和维护。以下是对Tomcat5.0各个目录的具体介绍: 1. *...

    tomcat startup.bat一闪而过.md

    当在 Windows 平台上启动 Tomcat 的 `startup.bat` 脚本时一闪而过的情况通常是因为命令提示符窗口无法长时间保持打开,而不是 Tomcat 启动过程中出现了问题。

Global site tag (gtag.js) - Google Analytics