Catalina 6.x 在 8.x 开始和结束

Catalina 6.x Start and stop bacome final in 8.x

x 我重写了 LifecycleBase.start() 方法,如下所示。但在 Catalina 8.x 中,此方法已成为最终方法。 谁能告诉我如何解决这个问题。 这是源代码

 public void start() throws LifecycleException
{       
    super.start();

    if(condition)
    {
        File checkDataFile = new File(DataFilePath);
        if(containerLog.isDebugEnabled())
            containerLog.debug("checking secureDataFile: " + checkDataFile.getAbsolutePath());

        another code ...
    }
    else
    {
        throw new LifecycleException("illegal arguments");
    }
}

public void stop() throws LifecycleException
{
    // sync via realm-object -> so the stop-event has to wait for active threads finishing their operations
    synchronized(this)
    {
        super.stop();
    }
}

您可以使用startInternal() and stopInternal(),这两种方法都是abstract protected,分别由start()stop()调用。

当然不要给 super.start()super.stop() 打电话,否则你会遇到 WhosebugError,因为 start()stop() 已经在给你打电话了自定义 "internal" 方法。

另从这两种方式仔细阅读合同:

startInternal()

Sub-classes must ensure that the state is changed to org.apache.catalina.LifecycleState.STARTING during the execution of this method. Changing state will trigger the org.apache.catalina.Lifecycle.START_EVENT event. If a component fails to start it may either throw a org.apache.catalina.LifecycleException which will cause it's parent to fail to start or it can place itself in the error state in which case stop() will be called on the failed component but the parent component will continue to start normally

stopInternal()

Sub-classes must ensure that the state is changed to org.apache.catalina.LifecycleState.STOPPING during the execution of this method. Changing state will trigger the org.apache.catalina.Lifecycle.STOP_EVENT event.

如果您想了解更多细节,请查看代码 的最新版本之一 org.apache.catalina.util.LifecycleBase.