Actually i have the requirement to execute a method which takes hours to complete on every machine reboot.I have deployed my web application on apache tomcat and i have enabled automatic start of Apache tomcat.For this I have called a method in ServletContextListener contextInitialized in a simple java class.Now my doubt is does the method called in contextInitialized will be executed each time the machine reboots.

Here is my ServletContextListener implemented class..

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();

}

and this is my web.xml..

 <listener>
    <listener-class>org.myapp.Startup</listener-class>
</listener>

Please guys help me .. Thanks in advance...

有帮助吗?

解决方案

have deployed my web application on apache tomcat and i have enabled automatic start of Apache tomcat.

Yes , for each start of Tomcat , ServletContextListener's contextInitialized method invokes.

其他提示

the method will be executed each time the tomcat starts.

If you don't want this, you can create a .jar library with a method main that you can invoke this from a cron that you can program when you want to execute.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top