研究僵局–第3部分

在本系列的前两个博客( 第1部分和第2部分)中 ,我演示了如何创建一段死锁的不良代码,然后使用该代码展示了进行线程转储的三种方式。 在这个博客中,我将分析线程转储以找出错误的原因。

下面的讨论同时涉及本系列第1部分中的AccountDeadlockDemo类,其中包含完整的代码清单。

我需要做的第一件事是从DeadlockDemo应用程序中进行线程转储,就像他们过去在Blue Peter上所说的那样:“这是我之前准备的”。

2012-10-16 13:37:03
Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.10-b01-428 mixed mode):"DestroyJavaVM" prio=5 tid=7f9712001000 nid=0x110247000 waiting on condition [00000000]
java.lang.Thread.State: RUNNABLE"Thread-21" prio=5 tid=7f9712944000 nid=0x118d76000 waiting for monitor entry [118d75000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366f58> (a threads.deadlock.Account)
- locked <7f3366ee0> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-20" prio=5 tid=7f971216c000 nid=0x118c73000 waiting for monitor entry [118c72000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366e98> (a threads.deadlock.Account)
- locked <7f3366f58> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-19" prio=5 tid=7f9712943800 nid=0x118b70000 waiting for monitor entry [118b6f000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366f40> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-18" prio=5 tid=7f9712942800 nid=0x118a6d000 waiting for monitor entry [118a6c000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366f40> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-17" prio=5 tid=7f9712942000 nid=0x11896a000 waiting for monitor entry [118969000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366ec8> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-16" prio=5 tid=7f9712941000 nid=0x118867000 waiting for monitor entry [118866000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366ec8> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-15" prio=5 tid=7f9712940800 nid=0x118764000 waiting for monitor entry [118763000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366ef8> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-14" prio=5 tid=7f971293f800 nid=0x118661000 waiting for monitor entry [118660000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366f28> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-13" prio=5 tid=7f97129ae000 nid=0x11855e000 waiting for monitor entry [11855d000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366eb0> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-12" prio=5 tid=7f97129ad000 nid=0x11845b000 waiting for monitor entry [11845a000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366f40> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-11" prio=5 tid=7f97129ac800 nid=0x118358000 waiting for monitor entry [118357000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366f58> (a threads.deadlock.Account)
- locked <7f3366eb0> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-10" prio=5 tid=7f97129ab800 nid=0x118255000 waiting for monitor entry [118254000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366eb0> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-9" prio=5 tid=7f97129ab000 nid=0x118152000 waiting for monitor entry [118151000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366e98> (a threads.deadlock.Account)
- locked <7f3366ec8> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-8" prio=5 tid=7f97129aa000 nid=0x11804f000 waiting for monitor entry [11804e000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366eb0> (a threads.deadlock.Account)
- locked <7f3366f28> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-7" prio=5 tid=7f97129a9800 nid=0x117f4c000 waiting for monitor entry [117f4b000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366eb0> (a threads.deadlock.Account)
- locked <7f3366e80> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-6" prio=5 tid=7f97129a8800 nid=0x117e49000 waiting for monitor entry [117e48000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366e80> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-5" prio=5 tid=7f97128a1800 nid=0x117d46000 waiting for monitor entry [117d45000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:81)
- waiting to lock <7f3366f28> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-4" prio=5 tid=7f97121af800 nid=0x117c43000 waiting for monitor entry [117c42000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366e80> (a threads.deadlock.Account)
- locked <7f3366e98> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-3" prio=5 tid=7f97121ae800 nid=0x117b40000 waiting for monitor entry [117b3f000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366e80> (a threads.deadlock.Account)
- locked <7f3366ef8> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"Thread-2" prio=5 tid=7f971224a000 nid=0x117a3d000 waiting for monitor entry [117a3c000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366eb0> (a threads.deadlock.Account)
- locked <7f3366f40> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)"RMI TCP Accept-0" daemon prio=5 tid=7f97128fd800 nid=0x117837000 runnable [117836000]
java.lang.Thread.State: RUNNABLE
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:408)
- locked <7f32ee740> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(ServerSocket.java:462)
at java.net.ServerSocket.accept(ServerSocket.java:430)
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:34)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:369)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:341)
at java.lang.Thread.run(Thread.java:680)"Poller SunPKCS11-Darwin" daemon prio=1 tid=7f97128fd000 nid=0x117734000 waiting on condition [117733000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at sun.security.pkcs11.SunPKCS11$TokenPoller.run(SunPKCS11.java:692)
at java.lang.Thread.run(Thread.java:680)"Low Memory Detector" daemon prio=5 tid=7f971209e000 nid=0x1173ec000 runnable [00000000]
java.lang.Thread.State: RUNNABLE"C2 CompilerThread1" daemon prio=9 tid=7f971209d000 nid=0x1172e9000 waiting on condition [00000000]
java.lang.Thread.State: RUNNABLE"C2 CompilerThread0" daemon prio=9 tid=7f971209c800 nid=0x1171e6000 waiting on condition [00000000]
java.lang.Thread.State: RUNNABLE"Signal Dispatcher" daemon prio=9 tid=7f971209b800 nid=0x1170e3000 waiting on condition [00000000]
java.lang.Thread.State: RUNNABLE"Surrogate Locker Thread (Concurrent GC)" daemon prio=5 tid=7f971209a800 nid=0x116fe0000 waiting on condition [00000000]
java.lang.Thread.State: RUNNABLE"Finalizer" daemon prio=8 tid=7f971209a000 nid=0x116d1c000 in Object.wait() [116d1b000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <7f3001300> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118)
- locked <7f3001300> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)"Reference Handler" daemon prio=10 tid=7f9712099000 nid=0x116c19000 in Object.wait() [116c18000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <7f30011d8> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:485)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
- locked <7f30011d8> (a java.lang.ref.Reference$Lock)"VM Thread" prio=9 tid=7f9712096800 nid=0x116b16000 runnable"Gang worker#0 (Parallel GC Threads)" prio=9 tid=7f9712002800 nid=0x1135c7000 runnable"Gang worker#1 (Parallel GC Threads)" prio=9 tid=7f9712003000 nid=0x1136ca000 runnable"Concurrent Mark-Sweep GC Thread" prio=9 tid=7f971204d800 nid=0x116790000 runnable
"VM Periodic Task Thread" prio=10 tid=7f97122d4000 nid=0x11793a000 waiting on condition"Exception Catcher Thread" prio=10 tid=7f9712001800 nid=0x1103ef000 runnable
JNI global references: 1037Found one Java-level deadlock:
=============================
"Thread-21":
waiting to lock monitor 7f97118bd560 (object 7f3366f58, a threads.deadlock.Account),
which is held by "Thread-20"
"Thread-20":
waiting to lock monitor 7f97118bc108 (object 7f3366e98, a threads.deadlock.Account),
which is held by "Thread-4"
"Thread-4":
waiting to lock monitor 7f9711834360 (object 7f3366e80, a threads.deadlock.Account),
which is held by "Thread-7"
"Thread-7":
waiting to lock monitor 7f97118b9708 (object 7f3366eb0, a threads.deadlock.Account),
which is held by "Thread-11"
"Thread-11":
waiting to lock monitor 7f97118bd560 (object 7f3366f58, a threads.deadlock.Account),
which is held by "Thread-20"Java stack information for the threads listed above:
===================================================
"Thread-21":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366f58> (a threads.deadlock.Account)
- locked <7f3366ee0> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-20":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366e98> (a threads.deadlock.Account)
- locked <7f3366f58> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-4":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366e80> (a threads.deadlock.Account)
- locked <7f3366e98> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-7":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366eb0> (a threads.deadlock.Account)
- locked <7f3366e80> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-11":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366f58> (a threads.deadlock.Account)
- locked <7f3366eb0> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)Found 1 deadlock.Heap
par new generation total 19136K, used 11590K [7f3000000, 7f44c0000, 7f44c0000)
eden space 17024K, 68% used [7f3000000, 7f3b51ac0, 7f40a0000)
from space 2112K, 0% used [7f40a0000, 7f40a0000, 7f42b0000)
to space 2112K, 0% used [7f42b0000, 7f42b0000, 7f44c0000)
concurrent mark-sweep generation total 63872K, used 0K [7f44c0000, 7f8320000, 7fae00000)
concurrent-mark-sweep perm gen total 21248K, used 8268K [7fae00000, 7fc2c0000, 800000000)

快速浏览,您可以看到此线程转储分为四个部分。 这些是:

  • 所有应用程序线程的完整列表
  • 死锁线程列表
  • 一小堆死锁线程
  • 应用程序的堆摘要


线程列表

上面第一点中的线程列表是所有应用程序线程及其当前状态的列表。 从中您可以看到应用程序由一堆线程组成,您可以将它们大致分为两部分。 首先,有后台线程。 这些是每个应用程序所拥有的,而这些作为我们作为应用程序程序员通常不需要担心的肮脏工作。 它们具有诸如“ DestroyJavaVM ”, Low Memory Detector, Finalizer, Exception Catcher Thread and Concurrent Mark-Sweep GC Thread DestroyJavaVM Low Memory Detector, Finalizer, Exception Catcher Thread and Concurrent Mark-Sweep GC Thread 。 其次,您或我可能会在我们的代码中创建一些线程。 这些名称通常包含由单词Thread和数字组成的名称。 例如: Thread-3, Thread-6 and Thread-20.

"Thread-20" prio=5 tid=7f971216c000 nid=0x118c73000 waiting for monitor entry [118c72000]
java.lang.Thread.State: BLOCKED (on object monitor)
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:82)
- waiting to lock <7f3366e98> (a threads.deadlock.Account)
- locked <7f3366f58> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:58)

详细查看Thread-20上提供的信息,您会发现它可以分为几部分。 这些是:

<td>线程20 <td>如上所述的线程名称。<tr> <td> prio = 5 <td>线程的优先级。 从1到10的数字,其中1是最低优先级,10是最高优先级。 <tr> <tr> <td> tid = 7f971216c000 <td>线程ID。 Thread.getId()调用返回的唯一数字。 <tr> <td> nid = 0x118c73000 <td>本机线程ID。 这映射到平台相关的线程ID。 <tr> <td>等待监视器输入[118c72000]

java.lang.Thread.State:阻塞(在对象监视器上)<td>这是线程的状态; 在这种情况下,它已被阻止。 还包括堆栈跟踪概述了线程被阻塞的位置。

请注意,线程也可以标记为守护程序。 例如:
“ RMI TCP Accept-0”守护进程prio = 5 tid = 7f97128fd800 nid = 0x117837000可运行[117836000] java.lang.Thread.State:可运行
守护程序线程是后台任务线程,例如上面列出的RMI TCP Accept-0线程。 守护程序线程是不会阻止JVM退出的线程。 仅保留守护程序线程时,JVM将退出或关闭。

但是,线程列表并不能真正帮助您找到死锁的原因,因此请快速前进...

死锁线程列表

线程转储的此部分包含死锁中涉及的所有线程的列表。

Found one Java-level deadlock:
=============================
"Thread-21":
waiting to lock monitor 7f97118bd560 (object 7f3366f58, a threads.deadlock.Account),
which is held by "Thread-20"
"Thread-20":
waiting to lock monitor 7f97118bc108 (object 7f3366e98, a threads.deadlock.Account),
which is held by "Thread-4"
"Thread-4":
waiting to lock monitor 7f9711834360 (object 7f3366e80, a threads.deadlock.Account),
which is held by "Thread-7"
"Thread-7":
waiting to lock monitor 7f97118b9708 (object 7f3366eb0, a threads.deadlock.Account),
which is held by "Thread-11"
"Thread-11":
waiting to lock monitor 7f97118bd560 (object 7f3366f58, a threads.deadlock.Account),
which is held by "Thread-20"

从上面的片段中,您可以看到有五个线程全部阻塞实例threads.deadlock.Account

撇开监视器ID和帐户实例,您可以看到“线程21”正在等待“线程20”,它正在等待“线程4”,而后者又正在等待“线程7”。 “线程7”正在等待“线程11”,这正在等待“线程20”:死锁循环,如下图所示:

死锁堆栈痕迹

难题的最后一部分是死锁线程堆栈跟踪的列表,如下所示:

Java stack information for the threads listed above:
===================================================
"Thread-21":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366f58> (a threads.deadlock.Account)
- locked <7f3366ee0> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-20":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366e98> (a threads.deadlock.Account)
- locked <7f3366f58> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-4":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366e80> (a threads.deadlock.Account)
- locked <7f3366e98> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-7":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366eb0> (a threads.deadlock.Account)
- locked <7f3366e80> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-11":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f3366f58> (a threads.deadlock.Account)
- locked <7f3366eb0> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)

从上一节中,我们知道Thread-20正在通过a回路径等待Thread-11Thread-11正在等待Thread-20 。 这是我们的僵局。

下一步是使用上面的线程堆栈跟踪将此死锁与代码行联系起来,我在下图中对此进行了简化。

在上图中,为清楚起见,我从对象ID中删除了7f3366前缀; 因此,对象7f3366f58现在是f58 。 从这个图中,可以看到该对象f58被锁定Thread-20上线59,并正在等待锁对象e98上线86.箭头下来,你可以看到, Thread-7正在等待锁eb0上线86,而这又是通过锁定Thread-11在线路59 Thread-11正在等待锁f58上线86,其,循环备份,对线58通过锁定Thread-20

那么,这些代码行在哪里? 下面显示了第59行:

…这是第86行:

有时每个人都会感到惊讶,上面的堆栈轨迹使我感到惊讶。 我期望锁位于85和86行。 但是,它们分别在59和86上。由于第59行不包含synced关键字,因此我猜测编译器已经对transfer(…)方法的第一个synced关键字进行了一些优化。

由此可以得出的结论是,从列表中随机选择两个Account对象的代码将它们以错误的顺序锁定在第59行和第86行。那么,解决方法是什么? 下次更多。 但是,还有最后一点需要注意,即每次在程序上生成线程转储时,死锁的组成可能都不相同。 再次运行DeadlockDemo程序并使用kill -3 PID来获取另一个线程转储后,我获得了以下结果:

Found one Java-level deadlock:
=============================
"Thread-20":
waiting to lock monitor 7fdc7c802508 (object 7f311a530, a threads.deadlock.Account),
which is held by "Thread-3"
"Thread-3":
waiting to lock monitor 7fdc7a83d008 (object 7f311a518, a threads.deadlock.Account),
which is held by "Thread-11"
"Thread-11":
waiting to lock monitor 7fdc7c802508 (object 7f311a530, a threads.deadlock.Account),
which is held by "Thread-3"Java stack information for the threads listed above:
===================================================
"Thread-20":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:86)
- waiting to lock <7f311a530> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-3":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:87)
- waiting to lock <7f311a518> (a threads.deadlock.Account)
- locked <7f311a530> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)
"Thread-11":
at threads.deadlock.DeadlockDemo$BadTransferOperation.transfer(DeadlockDemo.java:87)
- waiting to lock <7f311a530> (a threads.deadlock.Account)
- locked <7f311a518> (a threads.deadlock.Account)
at threads.deadlock.DeadlockDemo$BadTransferOperation.run(DeadlockDemo.java:59)Found 1 deadlock.

在此线程转储中,死锁中涉及的线程数量较少,但是如果您对其进行分析,则可以得出与我的第一个示例相同的结论。

下次:修改代码…

有关更多信息,请参阅本系列中的其他博客。

该系列以及其他博客的所有源代码都可以在Github上找到,网址为git://github.com/roghughe/captaindebug.git

参考: 调查死锁-第3部分: Captain Debug博客博客中来自JCG合作伙伴 Roger Hughes 的线程转储分析 。

翻译自: https://www.javacodegeeks.com/2012/11/investigating-deadlocks-part-3.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/370937.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

qq2009显ip版怎么用_毛孔粗大怎么破?用对方法,轻松改善显皮肤嫩滑

脸上毛孔粗大怎么破&#xff1f;超级烦恼尤其是一到秋季脸上经常油腻腻的为什么会毛孔粗大呢&#xff1f;毛孔粗大怎么破&#xff1f;用对方法&#xff0c;轻松改善显皮肤嫩滑 当皮肤老旧角质积聚越多&#xff0c;会使肌肤变厚、变粗糙&#xff0c;毛孔变粗大&#xff0c;肌肤也…

hello程序的运行过程-从计算机系统角度

hello程序的运行过程-从计算机系统角度 1、gcc编译器驱动程序读取源程序文件hello.c&#xff0c;并将它翻译成一个可执行目标文件hello。翻译过程分为四个阶段&#xff1a;预处理阶段&#xff0c;编译阶段&#xff0c;汇编阶段&#xff0c;链接阶段。 2、初始时&#xff0c;she…

Eclipse对类固醇的重构

在上一篇有关常见Java违规的文章中 &#xff0c;我列出了Java开发人员容易犯的一系列错误。 在重构Java项目以解决这些违规问题的同时&#xff0c;我广泛使用了Eclipse的重构功能来快速更改代码。 下面是这种重构技术的汇编。 1.在块级语句周围添加花括号 用{curly braces}包装…

微服务发展的历史_“美丽新羌 光照未来” 新羌社区开展微视频宣传片拍摄活动...

见圳客户端、深圳新闻网讯(记者 王志明 通讯员 甘力宇)为记录新羌社区的历史变迁&#xff0c;弘扬新羌人与时俱进、开拓进取的创新精神&#xff0c;宣传社区党委、社区一线工作者及社区居民的感人事迹和精神&#xff0c;展现深圳社区发展新风貌&#xff0c;2020年10月&#xff…

linux中扫描仪驱动程序,VueScan For Linux通用扫描仪驱动下载_VueScan For Linux通用扫描仪驱动官方下载-太平洋下载中心...

VueScan For Linux通用扫描仪驱动是一款提供 Linux 使用的图片扫描工具&#xff0c;它具有各种高级硬件能力使用非常广泛的的扫描仪软件&#xff0c;支持EPSon、HP、Nikon 和Canon 品牌的扫描仪设备&#xff0c;具有优良的色彩保真度和色彩平衡&#xff0c;可以让用户比平板扫描…

HTML head 头部中的各类标签

HTML <head> 头部 <head> 元素包含了所有的头部标签元素。在 <head>元素中你可以插入脚本&#xff08;scripts&#xff09;, 样式文件&#xff08;CSS&#xff09;&#xff0c;及各种meta信息。 可以添加在头部区域的元素标签为: <title>, <style&g…

CSS变量(自定义属性)实践指南

本文翻译自&#xff1a;https://www.sitepoint.com/practical-guide-css-variables-custom-properties/ 转载请注明出处&#xff1a;葡萄城官网&#xff0c;葡萄城为开发者提供专业的开发工具、解决方案和服务&#xff0c;赋能开发者。 Sass和Less这样的预处理器&#xff0c;让…

ffmpeg-win32-v3.2.4 下载_MVBOX下载|MVBOX 7.1.0.4官方版

还是要强调一句&#xff0c;现在市面上很多盗版或者免费的软件&#xff0c;都给一些黑客留下了暗门&#xff0c;所以大家还是支持正版比较好&#xff0c;不要贪图便宜使用盗版软件造成不好的后果。MVBOX播放器功能介绍1、在线卡拉OK2、虚拟摄像头3、画面调色板4、摄像头抠像5、…

饿了么商家电脑版_饿了么企业版荣膺“2020中国十大影响力人力资源品牌”大奖...

11月6日&#xff0c;由MeetHR GROUP主办的2020大中华地区HRVP高峰论坛在上海落幕。饿了么企业版凭借自身产品在人力资源管理与服务方面的创新实践&#xff0c;荣获“2020 中国十大影响力人力资源品牌(薪酬福利类)”殊荣。本次评选&#xff0c;据主办方介绍&#xff0c;旨在激励…

navicat连接linux远程数据库,使用Navicat forMySql远程连接Linux 系统上的数据库

使用Navicat for MySql远程连接Linux 系统上的数据库解决mysql"Access denied for userrootIP地址"问题1.问题说明&#xff1a;在MYSQL 中&#xff0c;用远程软件登陆服务器&#xff0c;有时出现&#xff1a;Access denied for user rootlocalhost出现这种问题&#…

HTTPS 通俗简介

为什么需要HTTPS 9个问题搞懂 https 来源 HTTP是明文传输的&#xff0c;也就意味着&#xff0c;介于发送端、接收端中间的任意节点都可以知道你们传输的内容是什么。这些节点可能是路由器、代理 等。 举个最常见的例子&#xff0c;用户登陆。用户输入账号&#xff0c;密码&am…

CSS Modules入门教程

为什么引入CSS Modules 或者可以这么说&#xff0c;CSS Modules为我们解决了什么痛点。针对以往我写网页样式的经验&#xff0c;具体来说可以归纳为以下几点&#xff1a; 全局样式冲突 过程是这样的&#xff1a;你现在有两个模块&#xff0c;分别为A、B,你可能会单独针对这两…

热电偶校验仪_热电偶校验方法_热电偶的使用方法及维修经验

一、遵照仪表接线图进行准确接线通电后&#xff0c;仪表先是显示仪表的热电偶分度号&#xff0c;接着显示仪表量程范围&#xff0c;再测仪表显示设定温度&#xff0c;数显仪表显示测量温度。若仪表数码管显示不是发热体的温度&#xff0c;而显示“OVER”、“0000”或“000”等状…

Java 7:满足Fork / Join框架

JSR-166&#xff08;y&#xff09;是Java 7中包含的此新功能的正式名称。如果您发现名称中有一个“ y”&#xff0c;这是因为自Java 5起就添加了JSR-166&#xff08;并发实用程序&#xff09; &#xff0c;但它不会就此停止&#xff0c;因为已经有计划在JSR-166&#xff08;e&a…

css3总结之居中

居中在前端布局上很常见&#xff0c;也很常用&#xff0c;也是最基本的技巧。居中效果在方向控制上基本可以分解成水平居中&#xff0c;垂直居中和水平垂直居中。 针对调整的元素不同&#xff0c;具体的处理方式上有些差异。这里我们先不讲绝对定位下的居中&#xff0c;绝对定位…

福州java培训哪里好_南通java培训哪家好

渡课IT教育成立于2006年&#xff0c;14年来&#xff0c;我们累计输送学员达 6000 &#xff0c;其中南通地区输送50%&#xff0c;上海 40%&#xff0c;其他地区 10%&#xff0c;学员1年后的平均薪水达 9860 元&#xff1b;受到1000用人单位的赞誉与支持。Java开发的需求量在北上…

研究僵局–第2部分

调查死锁时最重要的要求之一就是要研究死锁。 在我的上一个博客中&#xff0c;我编写了一个名为DeadlockDemo代码&#xff0c;该代码使用一堆线程在一系列银行帐户之间转移随机数&#xff0c;然后陷入僵局。 该博客运行该代码以演示获取线程转储的几种方法。 线程转储只是一个…

连锁便利店管理系统有什么用

连锁便利店管理系统对于连锁便利店的运营和管理非常有用。以下是一些常见的用途&#xff1a; 1. 库存管理&#xff1a;连锁便利店通常需要管理多个门店的库存&#xff0c;管理系统可以帮助实时掌握各个门店的库存情况&#xff0c;包括商品数量、进货记录、库存调拨等。这样可以…

浏览器打印设置横向打印_爱普生打印机无线连接设置

1、首先&#xff0c;把epsonl385打印机插上电源通电&#xff0c;待自检完成后&#xff0c;便可以设置。如果用户家里的无线路由器带有WPS(Wi-Fi Protected Setup)或QSS(又称快速安全设置)功能&#xff0c;那就简单多了。2、通过WPS或QSS无线路由器按钮连接&#xff0c;给无线路…

linux python定时任务调度,Python下定时任务框架APScheduler的使用

1.APScheduler简介&#xff1a;APScheduler是Python的一个定时任务框架&#xff0c;可以很方便的满足用户定时执行或者周期执行任务的需求&#xff0c;它提供了基于日期date、固定时间间隔interval 、以及类似于Linux上的定时任务crontab类型的定时任务。并且该框架不仅可以添加…