tomcat解析(九)StandardServer.initialize.start
2010-01-27 12:58
274 查看
在前几篇文章中已说到整个服务器的启动已托管给该类的initialize及start方法,下面我们来看一下这两个方法的内容
一.initialize
内容有三
1.lifecycle.fireLifecycleEvent(INIT_EVENT, null);
触发Lifecycle事件,将调用其LifecycleListener的相应方法,这里需要在XML文件里有配置,这里不细讲了
2.Registry.getRegistry(null, null).registerComponent(this, oname, null );
将该实例注册到MBeanFactory
3.services[i].initialize()
这里又将初始化的动作妥托给StandardService类的initialize进行
二.start()
内容有三
1.lifecycle.fireLifecycleEvent
触发Lifecycle.BEFORE_START_EVENT及Lifecycle.START_EVENT
2.((Lifecycle) services[i]).start();
妥拒给StandardService.start
3.lifecycle.fireLifecycleEvent
触发Lifecycle.AFTER_START_EVENT
StandardServer的默认Listener有如下几个
org.apache.catalina.core.AprLifecycleListener
org.apache.catalina.core.JasperListener
org.apache.catalina.mbeans.ServerLifecycleListener
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener
这几个监听器的工作无非就是初化一些类如JspRuntimeContext,将之前解析XML得到的对象以MBean方式进行注册及取消注册等
下一篇我们分别来看StandardService.initialize,start
一.initialize
/** * Invoke a pre-startup initialization. This is used to allow connectors * to bind to restricted ports under Unix operating environments. */ public void initialize() throws LifecycleException { if (initialized) { log.info(sm.getString("standardServer.initialize.initialized")); return; } lifecycle.fireLifecycleEvent(INIT_EVENT, null); initialized = true; if( oname==null ) { try { oname=new ObjectName( "Catalina:type=Server"); Registry.getRegistry(null, null) .registerComponent(this, oname, null ); } catch (Exception e) { log.error("Error registering ",e); } } // Register global String cache try { ObjectName oname2 = new ObjectName(oname.getDomain() + ":type=StringCache"); Registry.getRegistry(null, null) .registerComponent(new StringCache(), oname2, null ); } catch (Exception e) { log.error("Error registering ",e); } // Initialize our defined Services for (int i = 0; i < services.length; i++) { services[i].initialize(); } }
内容有三
1.lifecycle.fireLifecycleEvent(INIT_EVENT, null);
触发Lifecycle事件,将调用其LifecycleListener的相应方法,这里需要在XML文件里有配置,这里不细讲了
2.Registry.getRegistry(null, null).registerComponent(this, oname, null );
将该实例注册到MBeanFactory
3.services[i].initialize()
这里又将初始化的动作妥托给StandardService类的initialize进行
二.start()
/** * Prepare for the beginning of active use of the public methods of this * component. This method should be called before any of the public * methods of this component are utilized. It should also send a * LifecycleEvent of type START_EVENT to any registered listeners. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ public void start() throws LifecycleException { // Validate and update our current component state if (started) { log.debug(sm.getString("standardServer.start.started")); return; } // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null); lifecycle.fireLifecycleEvent(START_EVENT, null); started = true; // Start our defined Services synchronized (services) { for (int i = 0; i < services.length; i++) { if (services[i] instanceof Lifecycle) ((Lifecycle) services[i]).start(); } } // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null); }
内容有三
1.lifecycle.fireLifecycleEvent
触发Lifecycle.BEFORE_START_EVENT及Lifecycle.START_EVENT
2.((Lifecycle) services[i]).start();
妥拒给StandardService.start
3.lifecycle.fireLifecycleEvent
触发Lifecycle.AFTER_START_EVENT
StandardServer的默认Listener有如下几个
org.apache.catalina.core.AprLifecycleListener
org.apache.catalina.core.JasperListener
org.apache.catalina.mbeans.ServerLifecycleListener
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener
这几个监听器的工作无非就是初化一些类如JspRuntimeContext,将之前解析XML得到的对象以MBean方式进行注册及取消注册等
下一篇我们分别来看StandardService.initialize,start
相关文章推荐
- tomcat解析(十)StandardService.initialize.start
- Eclipse中部署项目时,Tomcat启动报错 “Failed to start component [StandardServer[8005]]”的解决
- tomcat(supplement)HttpConnector.initialize() 和 start() 方法 以及 StandardContext.start()方法的分析
- Tomcat启动报错 Failed to start component [StandardServer[8005]]解决
- tomcat解析(十五)StandardContext.start的其它内容
- Tomcat启动报错 Failed to start component [StandardServer[8005]]解决
- tomcat解析(十一)StandardEngine.start
- Tomcat启动报错 Failed to start component [StandardServer[8005]]解决
- The required Servercomponent failed to start so Tomcat is unable to start问题解决
- Server Tomcat v7.0 Server at localhost failed to start.
- Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds解决方案
- 【Web容器】Tomcat源码分析(2)-server.xml文件的加载与解析
- Server Tomcat Server at localhost failed to start解决方案
- tomcat启动时出现了Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]等错误
- Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds...
- Tomcat启动超时问题Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds
- Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds
- tomcat解析(三)bootstrap.load.start
- Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds. If the server requires
- Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds