实际上,我需要执行一个方法,每次机器重启都需要几个小时才能完成。我已经在 apache tomcat 上部署了我的 Web 应用程序,并且启用了 Apache tomcat 的自动启动。为此,我在 ServletContextListener 中调用了一个方法contextInitialized 在一个简单的 java 类中。现在我怀疑在 contextInitialized 中调用的方法是否会在每次机器重新启动时执行。
这是我的 ServletContextListener 实现类..
public class Startup implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
public void contextInitialized(ServletContextEvent sce) {
// Do your startup work here
System.out.println("Started....");
//captureCDRProcess();
new Thread(new Runnable() {
@Override
public void run() {
captureCDRProcess();
}
}).start();
}
这是我的 web.xml..
<listener>
<listener-class>org.myapp.Startup</listener-class>
</listener>
请大家帮帮我.. 提前致谢...
最佳答案
have deployed my web application on apache tomcat and i have enabled automatic start of Apache tomcat.
是的,对于 Tomcat 的每次启动,ServletContextListener
的 contextInitialized
方法都会调用。
关于java - ServletContextListener 是否调用每次机器重启时调用的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19998823/