Apache tomcat停止

时间:2017-08-29 14:22:55

标签: apache tomcat

在Apache中,您可以使用load_on_startup标记配置将加载该操作 我也希望在停止Apache使用stop tomcat命令执行多个操作时 有类似的东西吗?

10倍

2 个答案:

答案 0 :(得分:0)

我能想到的最接近的是“敲定一个servlet”

http://docs.oracle.com/javaee/6/tutorial/doc/bnags.html

Notifying Methods to Shut Down

To ensure a clean shutdown, your destroy method should not release any shared resources until all the service requests have completed. One part of doing this is to check the service counter. Another part is to notify the long-running methods that it is time to shut down. For this notification, another field is required. The field should have the usual access methods:

public class ShutdownExample extends HttpServlet {
    private boolean shuttingDown;
    ...
    //Access methods for shuttingDown
    protected synchronized void setShuttingDown(boolean flag) {
        shuttingDown = flag;
    }
    protected synchronized boolean isShuttingDown() {
        return shuttingDown;
    }
}

答案 1 :(得分:0)

如果要运行代码来处理特定于Tomcat的事物,请使用LifecycleListener,即创建一个实现LifecycleListener的类。

如果您想在应用程序启动时使用,请使用ServletListener。