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() 和 stopInternal(),这两种方法都是abstract protected
的,分别由start()
和stop()
调用。
当然,不要调用super.start()
和super.stop()
否则您将面临StackOverflowError
,因为start()
和stop()
已经在调用您的自定义"内部"方法。
还要仔细阅读这两种方法的合同:
startInternal()
子类必须确保在执行期间将状态更改为 org.apache.catalina.LifecycleState.STARTING。 此方法。更改状态将触发 org.apache.catalina.Lifecycle.START_EVENT事件。如果组件出现故障 要启动它,可能会抛出一个org.apache.catalina.Lifecycle Exception。 这将导致它的父级无法启动,或者它可以将自己放置 在错误状态下,在这种情况下,将在失败时调用 stop() 组件,但父组件将继续正常启动
和
停止内部()
子类必须确保状态更改为 org.apache.catalina.Lifecycle State.STOPING在执行期间 此方法。更改状态将触发 org.apache.catalina.Lifecycle.STOP_EVENT事件。
如果你想看看会发生什么细节,看看代码 最新版本之一 org.apache.catalina.util.Lifecycle Base .