Log4j Logger和Appender之间发生死锁

2023-12-12

我正在使用 LogAppender 类,它扩展了 Console Appender,并在日志级别为 ERROR 时在内部使用 Sendmail 函数发送邮件。 (我知道我可以使用 SMPT 附加程序进行邮件发送,但这就是基础设施的样子,所以请避免对此发表任何评论)。

我的应用程序被分成不同的线程,下面提到的问题偶尔会发生。(但一些观察告诉我,这可能是由于一个线程需要更多时间来初始化)。

我在 jstack 中得到以下转储:

    "pool-68-thread-1":
  waiting to lock Monitor@0x0000000005496818 (Object@0xfffffd7e390328b0, a crazycode/api/core/common/log/LogAppender),
  which is held by "main"
"main":
  waiting to lock Monitor@0x00000000064dbfc0 (Object@0xfffffd7dfb1f8908, a org/apache/log4j/Logger),
  which is held by "pool-68-thread-1"

Found a total of 1 deadlock.

Thread t@328: (state = BLOCKED)
 - org.apache.log4j.Category.callAppenders(org.apache.log4j.spi.LoggingEvent) @bci=13, line=202 (Interpreted frame)
 - org.apache.log4j.Category.forcedLog(java.lang.String, org.apache.log4j.Priority, java.lang.Object, java.lang.Throwable) @bci=14, line=388 (Interpreted frame)
 - org.apache.log4j.Category.log(java.lang.String, org.apache.log4j.Priority, java.lang.Object, java.lang.Throwable) @bci=34, line=853 (Compiled frame)
 - crazycode.team2Api.common.logging.DESLogger.debug(java.lang.Object) @bci=12, line=240 (Interpreted frame)
 - crazycode.api.core.cache.management.CacheFiller.refreshCache(java.util.List, java.lang.Object, java.lang.String) @bci=33, line=229 (Interpreted frame)
 - crazycode.api.core.cache.management.CacheFiller.initialize(java.lang.Object) @bci=70, line=285 (Interpreted frame)
 - crazycode.api.alert.impl.service.ResearchAlertConfigCacheImpl.init() @bci=18, line=110 (Interpreted frame)
 - crazycode.api.alert.impl.service.ResearchAlertConfigCacheImpl.initialize() @bci=1, line=98 (Interpreted frame)
 - crazycode.api.alert.handler.MemoHandler.initRealHandler() @bci=4, line=573 (Interpreted frame)
 - crazycode.api.alert.handler.RealAlertCoordinator.initHandler(crazycode.api.alert.handler.AlertHandler, int, int, boolean, boolean) @bci=61, line=47 (Interpreted frame)
 - crazycode.api.alert.handler.run.BaseAlertHandlerRun$1$1.run() @bci=72, line=229 (Interpreted frame)
 - java.util.concurrent.Executors$RunnableAdapter.call() @bci=4, line=441 (Interpreted frame)
 - java.util.concurrent.FutureTask$Sync.innerRun() @bci=30, line=303 (Interpreted frame)
 - java.util.concurrent.FutureTask.run() @bci=4, line=138 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor$Worker.runTask(java.lang.Runnable) @bci=59, line=886 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=28, line=908 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=662 (Interpreted frame)


Thread t@327: (state = BLOCKED)
 - org.apache.log4j.Category.callAppenders(org.apache.log4j.spi.LoggingEvent) @bci=13, line=202 (Interpreted frame)
 - org.apache.log4j.Category.forcedLog(java.lang.String, org.apache.log4j.Priority, java.lang.Object, java.lang.Throwable) @bci=14, line=388 (Interpreted frame)
 - org.apache.log4j.Category.log(java.lang.String, org.apache.log4j.Priority, java.lang.Object, java.lang.Throwable) @bci=34, line=853 (Compiled frame)
 - crazycode.team2Api.common.logging.DESLogger.debug(java.lang.Object) @bci=12, line=240 (Interpreted frame)
 - crazycode.api.core.cache.management.CacheFiller.refreshCache(java.util.List, java.lang.Object, java.lang.String) @bci=33, line=229 (Interpreted frame)
 - crazycode.api.core.cache.management.CacheFiller.initialize(java.lang.Object) @bci=70, line=285 (Interpreted frame)
 - crazycode.api.alert.impl.service.ResearchAlertConfigCacheImpl.init() @bci=18, line=110 (Interpreted frame)
 - crazycode.api.alert.impl.service.ResearchAlertConfigCacheImpl.initialize() @bci=1, line=98 (Interpreted frame)
 - crazycode.api.alert.handler.ResearchDocumentHandler.initRealHandler() @bci=86, line=957 (Interpreted frame)
 - crazycode.api.alert.handler.RealAlertCoordinator.initHandler(crazycode.api.alert.handler.AlertHandler, int, int, boolean, boolean) @bci=61, line=47 (Interpreted frame)
 - crazycode.api.alert.handler.run.BaseAlertHandlerRun$1$1.run() @bci=72, line=229 (Interpreted frame)
 - java.util.concurrent.Executors$RunnableAdapter.call() @bci=4, line=441 (Interpreted frame)
 - java.util.concurrent.FutureTask$Sync.innerRun() @bci=30, line=303 (Interpreted frame)
 - java.util.concurrent.FutureTask.run() @bci=4, line=138 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor$Worker.runTask(java.lang.Runnable) @bci=59, line=886 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=28, line=908 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=662 (Interpreted frame)


Thread t@322: (state = BLOCKED)
 - org.apache.log4j.Category.callAppenders(org.apache.log4j.spi.LoggingEvent) @bci=13, line=202 (Interpreted frame)
 - org.apache.log4j.Category.forcedLog(java.lang.String, org.apache.log4j.Priority, java.lang.Object, java.lang.Throwable) @bci=14, line=388 (Interpreted frame)
 - org.apache.log4j.Category.log(java.lang.String, org.apache.log4j.Priority, java.lang.Object, java.lang.Throwable) @bci=34, line=853 (Compiled frame)
 - crazycode.team2Api.common.logging.DESLogger.debug(java.lang.Object) @bci=12, line=240 (Interpreted frame)
 - crazycode.api.core.cache.management.CacheFiller.refreshCache(java.util.List, java.lang.Object, java.lang.String) @bci=33, line=229 (Interpreted frame)
 - crazycode.api.core.cache.management.CacheFiller.initialize(java.lang.Object) @bci=70, line=285 (Interpreted frame)
 - crazycode.api.alert.impl.service.ResearchAlertConfigCacheImpl.init() @bci=18, line=110 (Interpreted frame)
 - crazycode.api.alert.impl.service.ResearchAlertConfigCacheImpl.initialize() @bci=1, line=98 (Interpreted frame)
 - crazycode.api.alert.handler.RkdResearchDocumentHandler.initRealHandler() @bci=86, line=779 (Interpreted frame)
 - crazycode.api.alert.handler.RealAlertCoordinator.initHandler(crazycode.api.alert.handler.AlertHandler, int, int, boolean, boolean) @bci=61, line=47 (Interpreted frame)
 - crazycode.api.alert.handler.run.BaseAlertHandlerRun$1$1.run() @bci=72, line=229 (Interpreted frame)
 - java.util.concurrent.Executors$RunnableAdapter.call() @bci=4, line=441 (Interpreted frame)
 - java.util.concurrent.FutureTask$Sync.innerRun() @bci=30, line=303 (Interpreted frame)
 - java.util.concurrent.FutureTask.run() @bci=4, line=138 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor$Worker.runTask(java.lang.Runnable) @bci=59, line=886 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=28, line=908 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=662 (Interpreted frame)

有人可以阐明可能出现的问题以及解决问题的方法是什么吗?


今天我在自己的代码中看到了类似的跟踪。也许它也适用于你?

Summary:

  • 之前(死锁):logger.info(x); (where x是一个复杂的对象,它在内部获取读锁toString())
  • 之后(确定):logger.info(x.toString());

Details:

在我调用的一个线程中logger.info(x),这称为Category.callAppenders(LoggingEvent),它在附加程序上同步,然后调用x.toString(),它试图获取读锁x并被阻止。

在另一个线程中,我有一个方法来保持写锁x打电话时logger.info(""),也称为callAppenders,尝试在附加程序上同步,但被阻止。这是跟踪的相关部分:

Thread One [WAITING]
sun.misc.Unsafe.park(native method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireShared(AbstractQueuedSynchronizer.java:941)
java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireShared(AbstractQueuedSynchronizer.java:1261)
(... my ReadWriteLock$ReadLock.lock(Lock.java:256))
(... my Object's toString() ...)
org.apache.log4j.or.DefaultRenderer.doRender(DefaultRenderer.java:36)
org.apache.log4j.or.RendererMap.findAndRender(RendererMap.java:80)
org.apache.log4j.spi.LoggingEvent.getRenderedMessage(LoggingEvent.java:362)
org.apache.log4j.xml.XMLLayout.format(XMLLayout.java:148)
org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:302)
org.apache.log4j.WriterAppender.append(WriterAppender.java:160)
org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
org.apache.log4j.Category.callAppenders(Category.java:206)
org.apache.log4j.Category.forcedLog(Category.java:391)
org.apache.log4j.Category.log(Category.java:856)
Log.ndebug(Log.java:965)



Thread Two [BLOCKED; waiting to lock org.apache.log4j.Logger@1623f]
org.apache.log4j.Category.callAppenders(Category.java:204)
org.apache.log4j.Category.forcedLog(Category.java:391)
org.apache.log4j.Category.log(Category.java:856)
Log.debug(Log.java:820)
(.. something that acquires my reentrant ReadWriteLock$WriteLock ...)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Log4j Logger和Appender之间发生死锁 的相关文章

  • 多模块 Maven 项目中的 log4j

    如何在多模块 Maven 项目中实现 log4j 我是否将 log4j properties 文件添加到每个子模块的 src main resources 目录中 如果是这样 我是否必须为每个文件附加器指定不同的输出文件 或者有没有一种方法
  • 两个相同查询(不同参数)的 MySQL InnoDB 死锁问题

    我有下表 CREATE TABLE IF NOT EXISTS task id int 10 unsigned NOT NULL AUTO INCREMENT job id int 10 unsigned NOT NULL COMMENT
  • 为什么选择 XML 而不是属性文件来进行 Log4J 配置?

    是否有任何理由在 Log4J 配置中使用 XML 而不是属性文件 有一个有趣的讨论这篇博客中两者的优点 http www laliluna de log4j tutorial html 以下部分摘自该博客 属性可以由属性文件或 XML 文件
  • 为什么 SQL Server SET DEADLOCK_PRIORITY HIGH 不被遵守?

    我捕获了 SQL Server 2012 死锁图 使用盖尔 肖的 https www red gate com simple talk sql performance sql server deadlocks by example 查询 显
  • 这个递归同步调用如何不死锁?

    我有一组方法 它们全部同步到类对象 不能使用 self 因为可以在多个线程中使用该对象的多个实例 其中一些方法调用类中也在类对象上同步的其他方法 不知怎的 这有效并且不会导致我期望的僵局 我假设 testA 将被阻止运行 因为 testB
  • 将 System.out.println 记录到单个应用程序的日志文件

    我们在 tomcat 上有多个应用程序 它们使用 System out println 语句记录到 catalina out 有一个应用程序会创建大量日志语句 因此我想将这些应用程序输出记录到单独的日志文件中 我创建了一个 log4j xm
  • 如何让 log4j 根据日期和大小滚动文件?

    因此 log4j 附带了两个现有的日志滚轮 RollingFileAppender 和 DailyRollingFileAppender 有没有人听说过一个附加器可以完成前者的两种功能 我需要一个附加程序 它可以根据文件大小滚动日志文件 但
  • 在jsp页面中使用log4j的正确方法是什么

    我的意思是 我希望记录器名称反映 source jsp 文件 无论它是否包含在另一个文件中或编译为类或其他文件 首先 导入所需的包 即 then the jsppagename jsp根据您使用的服务器 可能会发生变化 然后 在 jsp 内
  • Java 优化器会删除空方法调用的参数构造吗?

    假设我有这样的代码 log info Now the amount amount seems a bit high 我将用虚拟实现替换 log 方法 例如 class Logger public void info 如果没有检测到副作用 优
  • 用户主目录中的 log4j 日志文件

    我正在开发一个可以在 OSX 和 Windows 上运行的应用程序 我希望将日志写入用户主目录 对于 OSX 它将位于 Users Library Application Support MyApp log 目录下 而在 Windows 下
  • 在 log4j.properties 文件 SMTP Appender 中隐藏或加密密码

    我正在使用自定义 gmail smtp 附加程序从我的 gmail 帐户发送错误日志 按照说明操作 http www tgerm com 2010 05 log4j smtpappender gmail custom html http w
  • 如何重新执行Log4j“默认初始化过程”?

    在运行时我经常创建 修改log4j记录器 附加器 级别 布局有时需要将所有内容重置回默认值 Log4j系统有明确的定义默认初始化过程 http logging apache org log4j 1 2 manual html default
  • 如何使用 Log4cxx 或 log4j 记录进程 ID

    我正在使用 log4cxx 我的项目 我可以使用 t 标记记录当前线程 id 如何在其中记录进程 id 或 log4j 我正在使用 ConversionPattern 和基于 xml 的配置文件 谢谢 基于以上答案 我将在 log4j 中执
  • log4j 中的异常深度

    我的 Myfaces 2 应用程序遇到实例化异常 但是通过 log4j 打印的异常会切断堆栈跟踪的其余部分 这是我所看到的 javax faces FacesException java lang InstantiationExceptio
  • 僵局澄清?

    也许对 死锁 还有其他解释 但据我所知 当发生死锁时两个线程各自等待一个资源 另一个 所以两者都无法继续 但我在这里看到了几个答案 它们声称长时间的等待 不互相等待 也是一个僵局 例子 1 https stackoverflow com a
  • Spark 执行器 STDOUT 到 Kubernetes STDOUT

    我在 Spark Worker 中运行的 Spark 应用程序将执行程序日志输出到特定文件路径 worker home directory app xxxxxxxx 0 stdout I used log4j properties将日志从
  • 自动检测log4j静态初始化错误的方法

    请注意 这更像是 Bash 问题 而不是 Java 问题 请参阅下面的注释 在每个类中配置log4j时 我们执行以下操作 public class Example private static final Logger log Logger
  • 在java中以原子方式获取多个锁

    我有以下代码 注意 为了可读性 我尽可能简化了代码 如果我忘记了任何关键部分 请告诉我 public class User private Relations relations public User relations new Rela
  • logback的“谨慎模式”是如何实现的?

    The 审慎模式 http logback qos ch manual appenders html prudentlogback 中的序列化所有 JVM 之间的 IO 操作 写入同一文件 可能运行在不同的主机上 在其他日志记录框架中 如果
  • 对象锁定私有类成员 - 最佳实践? (爪哇)

    I asked 类似的问题 https stackoverflow com questions 10548066 multiple object locks in java前几天 但对回复不满意 主要是因为我提供的代码存在一些人们关注的问题

随机推荐

  • 如何在 Ubuntu 操作系统上使用 cron 作业每天运行 php 脚本

    运行命令我正在使用 ubuntu 12 和 lamp 服务器 我想每 1 小时运行一次 php 脚本 我已经创建了一个 crontab 来执行此操作 如果我使用命令 crontab l 检查我的 cron 列表 它会显示如下 Edit th
  • 如何在 R 中将数据帧上传到 ndtv?

    我的目标是使用 R 中的三个包进行动态可视化 ndtv network and networkDynamic包 我创建了一个dataset根据此示例数据集排序的信息网络动态时间可视化研讨会 第 7 页 根据网络动态手册第49页 上传数据集并
  • 在模式弹出窗口中打开外部网站

    我知道 a href http www example com target blank Click here a 打开链接在新标签中 Chrome 和 Firefox 中的默认行为 a href http www example com
  • 通过 jQuery GET 强制“另存为”对话框

    我在下面的 test php 文件代码中调用 jQuery GET 我试图让脚本在生成的 test ini 文件上弹出 另存为 对话框 以允许将其保存在本地 然而 虽然我可以将结果回显给 jQuery 但我似乎无法弹出 另存为 对话框 更新
  • 如何将一系列单元格存储到数组中?

    如果我在单元格 A1 A150 中有一个数据列表 但数量可能会有所不同 有没有办法将其推入数组 而无需单独查看每个单元格来确定它是否为空 这样做超出了我的执行时间 我需要一种更快的方法来存储数据并在数据到达空单元格时停止 以下是我目前的做法
  • 当didUpdateToLocation发生时,iphone在后台发送邮件

    我开始工作 skpsmtpmessage http code google com p skpsmtpmessage 这样我就可以在前台发送邮件 现在我希望在 didUpdateLocation 发生时通过 skpsmtpmessage 在
  • 特定时间段内的多笔交易,受日期范围限制

    我有一个包含交易 人员 交易日期 物品等的数据库 每次有人购买商品时 交易都会存储在表中 如下所示 personNumber TransactionNumber TransactionDate ItemNumber 我想要做的是找到从 20
  • Java观察者更新函数

    我有一个实现观察者的类 当然它需要有更新功能 public void update Observable obs Object obj 谁能解释一下这两个参数代表什么 Observable 当然是我的 observable 但是 我如何通过
  • bash 中的 printf:“09”和“08”是无效数字,“07”和“06”可以

    这是我的 bash 脚本 我只想用零填充一组数字 printf 04d 09 printf 04d 08 printf 04d 07 printf 04d 06 Output rename sh line 3 printf 09 inval
  • 为什么不等待我传递给 Task.Run() 的异步操作?

    我在这里有一种非常奇怪的感觉 我错过了一些东西 但现在我已经在这个问题上苦苦挣扎了几个小时 但无法得到它 我有一种任务调度类 它主要接收它启动的正常同步操作 而不是通过 Task Run 异步操作 但是 当它收到传递的异步操作时 它会返回而
  • 事件侦听器无法与 firebase 查询一起使用

    我正在尝试为我的 firebase 查询脚本创建一个事件侦听器 但它的行为有点奇怪 这是我的脚本 using System Collections Generic using UnityEngine using System Linq us
  • NSAllowsArbitraryLoadsInWebContent in CN1

    我正在尝试解决 Apple 对 Codename One 的 http 限制 根据 iOS Cocoa 密钥文档 NSAllowsArbitraryLoadsInWebContent 将按照以下说明在 iOS 10 上运行 仅适用于要加载的
  • 在 PostgreSQL 中创建数据库的副本

    在 pgAdmin 中将整个数据库 其结构和数据 复制到新数据库的正确方法是什么 Postgres 允许在创建新数据库时使用服务器上任何现有的数据库作为模板 我不确定 pgAdmin 是否为您提供了创建数据库对话框上的选项 但如果没有 您应
  • 使用 Node.js 从 Azure WebJob 轮询 Azure 服务总线队列

    尝试使用用 Node js 编写的 WebJob 轮询 Azure 服务总线队列 我创建了 2 个 WebJobs 第一个是按需的 并向队列发送 10 条唯一的消息 第二个作业是连续的 并轮询队列中的消息 遇到以下问题 轮询速度很慢 平均需
  • 无法添加窗口——token null 无效;您的活动正在运行吗?

    我想在用户单击浮动图标时显示自定义弹出菜单 浮动图标是通过服务创建的 但我没有任何活动 这是我的浮动图标代码 public class copy actions service extends Service ImageView copy
  • 如何构建 less 的特定于 Rhino 的版本?

    我想运行最新版本less来自Java 为此 我相信 我需要Rhino特定版本的less 来自更少的网站 每个 less js 版本还包含 rhino 兼容版本 但这似乎已经是not案子自 v1 7 5 起 所以我安装了 NPM 安装了 Gr
  • 我可以使用eclipse编写j2me代码吗?

    请问各位 在我下载eclipse之前 是否可以使用它来编译j2me代码 或者它仅用于android应用程序 我发现 netbeans 很难使用 我想知道 eclipse 是否更容易 我是新人 我需要帮助来开始编写 j2me 以及使用 net
  • 如何将自定义CSS文件添加到Sphinx?

    如何添加自定义 css 文件 以下配置不起作用 conf py html static path static html theme default html theme options cssfiles static style css
  • Android studio 3不搜索库依赖项

    My Android studio stopped searching for library dependencies I know that it s better and faster to add dependencies thro
  • Log4j Logger和Appender之间发生死锁

    我正在使用 LogAppender 类 它扩展了 Console Appender 并在日志级别为 ERROR 时在内部使用 Sendmail 函数发送邮件 我知道我可以使用 SMPT 附加程序进行邮件发送 但这就是基础设施的样子 所以请避