문제

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