0

我有一个 Java servlet 过滤器,只要不再使用过滤器,它就应该清理一些资源。这是通过实施该Filter.destory方法来实现的。现在我想知道当整个servlet容器关闭时是否也会调用这个方法。因此,我想知道是否应该为此安装一个关闭挂钩。或者Filter.destroy当 servlet 容器关闭时总是调用该方法。

当我在关闭挂钩中设置断点时,我永远不会到达它。但我猜这是因为 IntelliJ 已经断开连接或其他类似的原因。这使得通过实验很难找出答案。

谢谢你的帮助!

4

1 回答 1

1

Using Jetty 6.1.22 Filter.destroy was called during shutdown. The spec just defines

Called by the web container to indicate to a filter that it is being taken out of service.

You should test it without IntelliJ, in a "real" environment, with a stand-alone tomcat or jetty.

Anyway, just to be safe, you could clean up both in Filter.destroy and ServletContextListener.contextDestroyed. In that case synchronize your filter clean up. And make sure, if you clean up twice, that the 2nd run does not fail with an exception etc.

于 2013-07-10T12:41:30.187 回答