欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2024-02-28 20:04:04
...

结论一,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!!");
	}

}