于是回到了StandardServer自己的init和start方法,
protected void startInternal() throws LifecycleException { this.fireLifecycleEvent("configure_start", (Object)null); this.setState(LifecycleState.STARTING); this.globalNamingResources.start(); Object var1 = this.servicesLock; synchronized(this.servicesLock) { for(int i = 0; i < this.services.length; ++i) { this.services[i].start(); } } }
总得来说就是,StandardServer继承自LifecycleMBeanBase,而LifecycleMBeanBase继承自LifecycleBase,而LifecycleBase类中的模板方法,又让自己的子类去进行具体的实现,但是我们要知道他的Tomcat生命周期中存在这些内容才行。
图中都说了,Server里面有Service,那么一定就有,我们得去找找看,于是阿粉再次去找并且去看它到底是个什么意思,
public void addService(Service service) { service.setServer(this); Object var2 = this.servicesLock; synchronized(this.servicesLock) { Service[] results = new Service[this.services.length + 1]; System.arraycopy(this.services, 0, results, 0, this.services.length); results[this.services.length] = service; this.services = results; if (this.getState().isAvailable()) { try { service.start(); } catch (LifecycleException var6) { ; } } this.support.firePropertyChange("service", (Object)null, service); } }
位置是在Server的接口中出现了增加和删除Service的方法,Server的init方法和start方法循环去调用每个Service的init方法和start方法。
接下来我们看看Service的具体实现,找到StandardService:
protected void initInternal() throws LifecycleException { super.initInternal(); if (this.engine != null) { this.engine.init(); } Executor[] arr$ = this.findExecutors(); int len$ = arr$.length; int len$; for(len$ = 0; len$ < len$; ++len$) { Executor executor = arr$[len$]; if (executor instanceof JmxEnabled) { ((JmxEnabled)executor).setDomain(this.getDomain()); } executor.init(); } this.mapperListener.init(); Object var11 = this.connectorsLock; synchronized(this.connectorsLock) { Connector[] arr$ = this.connectors; len$ = arr$.length; for(int i$ = 0; i$ < len$; ++i$) { Connector connector = arr$[i$]; try { connector.init(); } catch (Exception var9) { String message = sm.getString("standardService.connector.initFailed", new Object[]{connector}); log.error(message, var9); if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE")) { throw new LifecycleException(message); } } } } }
而在方法中主要调用Executor,mapperListener,executor的init方法。
connector之前已经有了,而这个mapperListener就是Mapper的监听器,用来坚挺container容器的变化。
文献参考
《深入剖析Tomcat》
《Tomcat架构解析》
《Servlet/JSP深入详解》