Tomcat启动完成后再执行一个指定的方法 - 不影响Tomcat的启动时间

来源:互联网 发布:c语言写俄罗斯方块 编辑:程序博客网 时间:2024/05/06 00:55

http://www.tuicool.com/articles/B7RNnev



1.下面两个方法,如果过长 的话会导致超时

web.xml
<listener>
 
  <listener-class>com.PreloadListener</listener-class>
</listener>
java代码
public class PreloadListener implementsServletContextListener{
  public void contextInitialized(ServeltContextEvent sce){
    //init operation
  }
  public void contextDestoryed(ServeltContextEvent sce){
    //destory operation
  }
}

2.
Java代码
public class ClassName extends HttpServlet {

    public voidinit() throws ServletException {
           //把要做的事写到这里
        }
}
web.xml文件中加上
<servlet>
0 0
原创粉丝点击