启动default servlet

basic info

  • servlet-name: default
  • servlet-class: org.apache.catalina.servlets.DefaultServlet

线程调用栈,请求时序图

启动命令:org.apache.catalina.startup.Bootstrap start (见catalina.sh)

  • Bootstrap.main(String[]) //

    1. bootstrap.init(),主要是catalinaDaemon = new Catalina()
    2. bootstrap.load() 主要根据server.xml的配置new StandardServer()

      • Method.invoke(Object, Object…) // 调用org.apache.catalina.startup.Catalina.load(“start”)
      • Catalina.load(String[]) // 1. 读取server.xml 2.new StandardServer(),(server = StandardServer[8005]) 3. server.setCatalina(this)

      Digester.parse(InputSource) line: 1536
      Catalina.load()

Bootstrap.load(String[]) //  主要

Tomcat admin port 8005
catalina实例是什么时候new的?

1
2
3
4
5
6
7
8
9
10
11
12
StandardWrapper.initServlet(Servlet) //
StandardWrapper.loadServlet() // 1. servlet = newInstance(servletClass) 2. initServlet(servlet) 3.
StandardWrapper.load() //
StandardContext.loadOnStartup(Container[]) //
StandardContext.startInternal() //
StandardContext(LifecycleBase).start()
ContainerBase$StartChild.call() // child.start(); 其中StandardContext child=StandardEngine[Catalina].StandardHost[localhost].StandardContext[]
ContainerBase$StartChild.call() // 这是个inner class
FutureTask<V>.run()
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
ThreadPoolExecutor$Worker.run()
Thread.run()

疑问: 这里为什么没看到engine、host、connector、service的影子

启动 jsp servlet

  • servlet-name: jsp
  • servlet-class: org.apache.jasper.servlet.JspServlet

启动 HelloWorldExample

访问 HelloWorldExample

start log

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
七月 25, 2016 6:56:04 下午 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\java\jdk1.7.0_67\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/java/jdk1.7.0_67/bin/../jre/bin/server;C:/Program Files/java/jdk1.7.0_67/bin/../jre/bin;C:/Program Files/java/jdk1.7.0_67/bin/../jre/lib/amd64;C:\Python27\Lib\site-packages\PyQt4;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\IBM\Infoprint Select;C:\Program Files\java\jdk1.7.0_67\bin;C:\Program Files\java\jdk1.7.0_67\jre\bin;C:\Python27;C:\texlive\2015\bin\win32;C:\Program Files\nodejs\;C:\Program Files\apache-maven-3.3.9\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\TortoiseSVN\bin;C:\Users\IBM_ADMIN\Anaconda2;C:\Users\IBM_ADMIN\Anaconda2\Scripts;C:\Users\IBM_ADMIN\Anaconda2\Library\bin;C:\Users\IBM_ADMIN\AppData\Roaming\npm;C:\Wind\Wind.NET.Client\WindNET\bin\;C:\Program Files\Git\cmd;;E:\software\eclipsejavaee;;.
七月 25, 2016 6:56:04 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:tomcat-example' did not find a matching property.
// 上一行的原因来自于server.xml中的配置
// <Context docBase="tomcat-example" path="/tomcat-example" reloadable="true" source="org.eclipse.jst.jee.server:tomcat-example"/>
// 这个配置是由eclipse自动生成的,不用管
七月 25, 2016 6:56:04 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
七月 25, 2016 6:56:04 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
七月 25, 2016 6:56:04 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1026 ms
七月 25, 2016 6:56:04 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
七月 25, 2016 6:56:04 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.47
七月 25, 2016 6:56:05 下午 org.apache.catalina.util.SessionIdGenerator createSecureRandom
信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [217] milliseconds.
七月 25, 2016 6:56:17 下午 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
七月 25, 2016 6:56:17 下午 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
七月 25, 2016 6:56:25 下午 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@44608238')
七月 25, 2016 6:56:25 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
七月 25, 2016 6:56:25 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
七月 25, 2016 6:56:25 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 21375 ms