大家好。
我无法解决下一个问题:
我们正在为我们的应用程序使用 WebSphere 应用程序服务器,并使用“logback”日志记录框架来管理我们的日志文件。
似乎一切都工作正常,但最近我们检测到文件滚动的 Not Acceptable 行为。 对于我们在 WebSphere 上的应用程序的首次启动,滚动日志文件(按大小和天数)运行良好,但是当我们停止应用程序时 - 当前日志文件被 java.exe(IBM WAS) 进程锁定,并且当我们再次启动应用程序时 -由于先前的锁定,滚动日志不起作用。当我通过 windows Unlocker 查看该文件时,我很惊讶 - 有 2 个进程锁定当前文件。如果我们停止应用程序并再次启动它 - 将有 3 个 java.exe 锁定当前日志文件,尽管在任务管理器中只运行一个进程。有时我在这样的“测试”过程中发现 OutOfMemory 错误。
因此,我们最后有非常大的日志文件。 (20GB 及以上)
我发现了一些类似的问题,但是 log4j 滚动。并且没有任何解释为什么会这样 - 只有一个是 - log4j 不推荐用于 websphere。
而且似乎问题根本不完全在“记录器”中。 那么,有没有人可以回答 2 个问题 -
<小时/>当应用程序已经停止时,为什么 WebSphere 会锁定文件而不释放它???
当应用程序以正确的方式停止时(不使用 Unlocker、任务管理器等作弊工具),如何释放(或告诉 WebSphere 不要锁定)日志文件的锁定?
感谢您的关注...如有任何帮助,我们将不胜感激。
<小时/>更新1:
最近我尝试使用带有 logback 的小型网络应用程序 - 而且效果很好 - 没有重复锁定。
当我们的大型应用程序停止时,我还查看了日志,并发现了这一点(停止应用程序期间日志中唯一的一个字符串)
27-03 05:59:39 [WebContainer: 7] INFO o.hibernate.impl.SessionFactoryImpl:close - 关闭
关闭但未关闭?我希望我能以正确的方式思考......
----UPD 3
嗯...我花了很多时间在 websphere 上部署自定义 WAR,但我仍然无法找出为什么有时 WAS 会锁定日志文件,有时却不会。
我不敢相信,也很惊讶没有人遇到同样的麻烦
最佳答案
这篇文章确实对我有帮助 - http://logback.qos.ch/manual/jmxConfig.html 尽管我们在应用程序中没有使用任何 JMXConfigurator ...
所以我在 web.xml 中添加了
<listener>
<listener-class>ru.fns.commonex.listener.CleanUpServletContextListener</listener-class>
</listener>
监听器有下一个代码:
@Override
public void contextDestroyed(ServletContextEvent sce) {
log.debug("contextDestroyed({}) called.", sce);
deRegisterLog();
}
/**
* Avoiding memory leaks
*
* If your application is deployed in a web-server or an application server,
* the registration of an JMXConfigurator instance creates a reference from the system class loader
* into your application which will prevent it from being garbage collected when it is stopped or re-deployed,
* resulting in a severe memory leak.
*
* Thus, unless your application is a standalone Java application,
* you MUST unregister the JMXConfigurator instance from the JVM's Mbeans server.
* Invoking the reset() method of the appropriate LoggerContext will automatically unregister any
* JMXConfigurator instance. A good place to reset the logger context is in the contextDestroyed()
* method of a javax.servlet.ServletContextListener.
*/
private void deRegisterLog() {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
log.info("Trying to stop logger factory {}", lc);
if (lc != null) {
lc.stop();
}
}
关于java - Websphere 和 QOS 日志返回 : log-files are locked for rolling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15628546/