// org.apache.catalina.util.LifecycleBase#start@Overridepublicfinalsynchronizedvoidstart()throwsLifecycleException{if(LifecycleState.STARTING_PREP.equals(state)||LifecycleState.STARTING.equals(state)||LifecycleState.STARTED.equals(state)){if(log.isDebugEnabled()){Exception e =newLifecycleException();
log.debug(sm.getString("lifecycleBase.alreadyStarted",toString()), e);}elseif(log.isInfoEnabled()){
log.info(sm.getString("lifecycleBase.alreadyStarted",toString()));}return;}if(state.equals(LifecycleState.NEW)){// 注意:因为tomcat组件均是LifecycleBase的子类,故需要区分当前类型// 当前还处于 tomcat.server.service.connect 初始化完成的阶段init();}elseif(state.equals(LifecycleState.FAILED)){stop();}elseif(!state.equals(LifecycleState.INITIALIZED)&&!state.equals(LifecycleState.STOPPED)){invalidTransition(Lifecycle.BEFORE_START_EVENT);}try{setStateInternal(LifecycleState.STARTING_PREP,null,false);// step into ...// 接下来即 tomcat.server.service.connect 启动阶段startInternal();if(state.equals(LifecycleState.FAILED)){// This is a 'controlled' failure. The component put itself into the// FAILED state so call stop() to complete the clean-up.stop();}elseif(!state.equals(LifecycleState.STARTING)){// Shouldn't be necessary but acts as a check that sub-classes are// doing what they are supposed to.invalidTransition(Lifecycle.AFTER_START_EVENT);}else{setStateInternal(LifecycleState.STARTED,null,false);}}catch(Throwable t){// This is an 'uncontrolled' failure so put the component into the// FAILED state and throw an exception.handleSubClassException(t,"lifecycleBase.startFail",toString());}}// org.apache.catalina.connector.Connector#startInternal@OverrideprotectedvoidstartInternal()throwsLifecycleException{// Validate settings before startingif(getPort()<0){thrownewLifecycleException(sm.getString("coyoteConnector.invalidPort",Integer.valueOf(getPort())));}setState(LifecycleState.STARTING);try{// step into ...// 这里调用了 protocol 的启动方法
protocolHandler.start();}catch(Exception e){thrownewLifecycleException(
sm.getString("coyoteConnector.protocolHandlerStartFailed"), e);}}------------------------@Overridepublicvoidstart()throwsException{if(getLog().isInfoEnabled()){getLog().info(sm.getString("abstractProtocolHandler.start",getName()));}// step into ...// 现在的情况就是:protocol的启动过程调用了endpoint的启动方法
endpoint.start();// Start async timeout thread
asyncTimeout =newAsyncTimeout();Thread timeoutThread =newThread(asyncTimeout,getNameInternal()+"-AsyncTimeout");int priority = endpoint.getThreadPriority();if(priority <Thread.MIN_PRIORITY || priority >Thread.MAX_PRIORITY){
priority =Thread.NORM_PRIORITY;}
timeoutThread.setPriority(priority);
timeoutThread.setDaemon(true);
timeoutThread.start();}------------------// org.apache.tomcat.util.net.AbstractEndpoint#startpublicfinalvoidstart()throwsException{// 我们前面初始化的时候已经执行过Bind()方法了,并且还设置了状态BOUND_ON_INIT// 故,这里不会再执行了if(bindState ==BindState.UNBOUND){bind();
bindState =BindState.BOUND_ON_START;}// step into ...startInternal();}