`
yutiansky
  • 浏览: 194323 次
  • 性别: Icon_minigender_1
  • 来自: 本溪
社区版块
存档分类
最新评论

(java入门)tomcat的webapps加载调查

阅读更多

结论一,webapp加载顺序和卸载顺序正好相反。

结论二,加载是单线程,顺序加载。

 

package net.tianyu.sample;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class SampleServletListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent sce) {

		ServletContext sc = sce.getServletContext();
		String applicationName = (String) sc.getInitParameter("ApplicationName");
		System.out.println("==" + applicationName + " : before OVER!!");
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("==" + applicationName + " : after OVER!!");
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {

		ServletContext sc = sce.getServletContext();
		String applicationName = (String) sc.getInitParameter("ApplicationName");
		System.out.println("==" + applicationName + " : before START!!");
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("==" + applicationName + " : after START!!");
	}

}

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics