(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!!");
	}

}

 

 

 

你可能感兴趣的:(java,thread,tomcat,.net,servlet)