Jboss EAP 6.3线程使用log4j ConsoleAppender获得死锁

时间:2015-05-07 11:09:06

标签: java jboss log4j jboss7.x deadlock

从Jboss 5升级到Jboss EAP 6.3.0后,我们发现应用程序在运行一段时间后失败。看一下,它开始增加接受HTTP请求但无法为它们提供服务的线程数。之后,ThreadDump向我们展示了log4j的死锁:

Found one Java-level deadlock:
=============================
"http-/0.0.0.0:39002-109":
  waiting to lock monitor 0x0000000013d2a218 (object 0x00000000c1cc7aa8, a org.apache.log4j.ConsoleAppender),
  which is held by "http-/0.0.0.0:39002-12"
"http-/0.0.0.0:39002-12":
  waiting to lock monitor 0x000000001456c128 (object 0x00000000c1cca400, a java.io.PrintStream),
  which is held by "http-/0.0.0.0:39002-74"
"http-/0.0.0.0:39002-74":
  waiting to lock monitor 0x0000000013d2a218 (object 0x00000000c1cc7aa8, a org.apache.log4j.ConsoleAppender),
  which is held by "http-/0.0.0.0:39002-12"

与开发团队一起在应用程序内部删除了对log4j的所有引用,只留下standalone.xml上的配置,以便将某些类记录到某些特定文件中,这是有关日志记录的相关配置:

    <periodic-rotating-file-handler name="FILE" autoflush="true">
        <formatter>
            <named-formatter name="PATTERN"/>
        </formatter>
        <file relative-to="jboss.server.log.dir" path="server.log"/>
        <suffix value=".yyyy-MM-dd"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <size-rotating-file-handler name="DocumentalServices">
        <file relative-to="jboss.server.log.dir" path="DocumentalServices.log"/>
        <rotate-size value="10m"/>
        <max-backup-index value="5"/>
    </size-rotating-file-handler>
    <size-rotating-file-handler name="DataServices">
        <file relative-to="jboss.server.log.dir" path="DataServices.log"/>
        <rotate-size value="10m"/>
        <max-backup-index value="5"/>
    </size-rotating-file-handler>
    <size-rotating-file-handler name="Audit">
        <file relative-to="jboss.server.log.dir" path="audit.log"/>
        <rotate-size value="10m"/>
        <max-backup-index value="5"/>
    </size-rotating-file-handler>
    <logger category="com.documentation.framework.ws" use-parent-handlers="false">
        <level name="DEBUG"/>
        <handlers>
            <handler name="DocumentalServices"/>
        </handlers>
    </logger>
    <logger category="com.documentation.framework.data" use-parent-handlers="false">
        <level name="DEBUG"/>
        <handlers>
            <handler name="DataServices"/>
        </handlers>
    </logger>
    <logger category="com.documentation.framework.core.audit" use-parent-handlers="false">
        <level name="DEBUG"/>
        <handlers>
            <handler name="Audit"/>
        </handlers>
    </logger>
    <root-logger>
        <level name="INFO"/>
        <handlers>
            <handler name="FILE"/>
        </handlers>
    </root-logger>

看来ConsoleAppender上的死锁有点奇怪,记住我们没有登录到root-logger中的控制台,只是登录到FILE(server.log)。

1 个答案:

答案 0 :(得分:1)

必须添加log4j ConsoleAppender。它可能是Spring,因为我知道他们做了一些记录技巧。在启动期间,您可以尝试传递-Dorg.jboss.as.logging.per-deployment=false,如果找到log4j.xml或log4j.properties文件,则应禁用JBoss EAP尝试配置log4j。

另一个选项可能是在日志记录子系统中将add-logging-api-dependencies设置为false。您需要在部署中包含一个log4j库,因为它似乎取决于它。这是CLI改变默认值的样子。

/subsystem=logging:write-attribute(name=add-logging-api-dependencies,value=false)

请注意,禁用此功能会影响所有部署。

那说问题就是log4j ConsoleAppender的工作方式。它始终直接记录到System.xxx。 JBoss EAP将stdoutstderr包装在记录器中,这是导致死锁的原因。

有一个修复程序应该在6.4版本中结束。