tomcat4 reload的实现原理

来源:岁月联盟 编辑:exp 时间:2012-03-07
1.在ContainerBase的setLoader中,loader.setContainer(this);
2.调用了WepappLoader的setContainer()
        if ((this.container != null) && (this.container instanceof Context)) {  //如果是上下文容器
            setReloadable( ((Context) this.container).getReloadable() );
            ((Context) this.container).addPropertyChangeListener(this);
        }
3.在setReloadable(boolean reloadable)中启动线程 持续的检查WEB-INF目录下面的类文件和JAR文件的时间戳  threadStart();
4.threadStart 启动同类的start()方法:产生新的一个线程,调用run()reload class, 产生threadStart()
5.run()中notifyContext();WebappContextNotifier notifier = new WebappContextNotifier();
        (new Thread(notifier)).start();
6.WebappContextNotifier为内部类,只有run()一个方法,执行((Context) container).reload(); 调用StandardContext的reload()方法
7. StandardContext的reload()方法的业务逻辑:
   7.1 Shut down our session manager
   7.2 Shut down the current version of all active servlets
   7.3 Shut down application event listeners
   7.4 Clear all application-originated servlet context attributes
   7.5 Shut down filters
   7.6 Shut down our application class loader
   7.7 Restart our application class loader
   7.8 Restart our application event listeners and filters
   7.9 Restore the "Welcome Files" and "Resources" context attributes
   7.10 Restart our currently defined servlets  :((Lifecycle) wrapper).start();
   7.11 Reinitialize all load on startup servlets:loadOnStartup(children);
   7.12 Restart our session manager
8.loadOnStartup(Container children[])-->wrapper.load()-->StandardWarpper loadServlet();
 
从代码上看,servlet是动态的全部先卸载,然后全部加载。

作者 rain