如何从挂起的 Java Swing 应用程序中解释此线程转储?

how to interprete this thread dump from a hung Java Swing application?

我有以下 thread dump 来自 hung java swing 应用程序。它在单击 按钮 并且 GUI 变为空白后挂起。套接字通信和任务管理中的其他线程仍在工作(从日志文件我可以看出)。我删除了一些不相关的输出。

#13 AW-EventQueue-0 应该通过套接字发送命令,但似乎在那里失败了。 #20#21 是 AW-EventQueue-0-SharedResourceRunner 这是不一样的作为#13?似乎没有死锁,但 GUI 没有响应并变成空白。

您是否看到任何关于挂起原因的有用信息?

Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.20-b23 mixed mode):

"DestroyJavaVM" #32 prio=5 os_prio=0 tid=0x00007f286c009800 nid=0xa41 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"TimerQueue" #22 daemon prio=5 os_prio=0 tid=0x00007f28002a8800 nid=0xa65 waiting on condition [0x00007f284c56f000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x0000000088a8f5c0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at java.util.concurrent.DelayQueue.take(DelayQueue.java:211)
        at javax.swing.TimerQueue.run(TimerQueue.java:171)
        at java.lang.Thread.run(Thread.java:745)

"AWT-EventQueue-0-SharedResourceRunner" #21 daemon prio=6 os_prio=0 tid=0x00007f280021d000 nid=0xa64 in Object.wait() [0x00007f284d434000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000088aec748> (a jogamp.opengl.SharedResourceRunner)
        at java.lang.Object.wait(Object.java:502)
        at jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:276)
        - locked <0x0000000088aec748> (a jogamp.opengl.SharedResourceRunner)
        at java.lang.Thread.run(Thread.java:745)

"AWT-EventQueue-0-SharedResourceRunner" #20 daemon prio=6 os_prio=0 tid=0x00007f28001f3000 nid=0xa63 in Object.wait() [0x00007f284f7f5000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000088aed588> (a jogamp.opengl.SharedResourceRunner)
        at java.lang.Object.wait(Object.java:502)
        at jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:276)
        - locked <0x0000000088aed588> (a jogamp.opengl.SharedResourceRunner)
        at java.lang.Thread.run(Thread.java:745)

"AWT-EventQueue-0" #13 prio=6 os_prio=0 tid=0x00007f286c444800 nid=0xa59 in Object.wait() [0x00007f2858913000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000000dc467018> (a java.lang.Object)
        at java.lang.Object.wait(Object.java:502)
        at com.mycp.common.task.BMBTaskBase.startTask(BMBTaskBase.java:551)
        - locked <0x00000000dc467018> (a java.lang.Object)
        at com.mycp.uiapp.workmgmt.WorkMgmtMgr.sendBegCmd(WorkMgmtMgr.java:334)
        at com.mycp.uiapp.workmgmt.WorkMgmtPanelBase.prepareAndSendBegWork(WorkMgmtPanelBase.java:559)
        at com.mycp.uiapp.workmmgmt.WorkMgmtPanel.prepareAndSendBegWork(WorkMgmtPanel.java:1479)
        at com.mycp.uiapp.workmgmt.WorkMgmtPanelBase.btnPrepareClicked(WorkMgmtPanelBase.java:363)
        at com.mycp.uiapp.workmgmt.WorkMgmtPanel.btnPrepareClicked(WorkMgmtPanel.java:1412)
        at com.mycp.uiapp.workmgmt.WorkMgmtPanel.actionPerformed(WorkMgmtPanel.java:1336)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)

"AWT-Shutdown" #14 prio=5 os_prio=0 tid=0x00007f286c443000 nid=0xa58 in Object.wait() [0x00007f2858a17000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000088ae8c28> (a java.lang.Object)
        at java.lang.Object.wait(Object.java:502)
        at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:295)
        - locked <0x0000000088ae8c28> (a java.lang.Object)
        at java.lang.Thread.run(Thread.java:745)

"AWT-XAWT" #12 daemon prio=6 os_prio=0 tid=0x00007f286c384000 nid=0xa51 runnable [0x00007f285914f000]
   java.lang.Thread.State: RUNNABLE
        at sun.awt.X11.XToolkit.waitForEvents(Native Method)
        at sun.awt.X11.XToolkit.run(XToolkit.java:559)
        at sun.awt.X11.XToolkit.run(XToolkit.java:523)
        at java.lang.Thread.run(Thread.java:745)

"Java2D Disposer" #10 daemon prio=10 os_prio=0 tid=0x00007f286c35e000 nid=0xa50 in Object.wait() [0x00007f2859250000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000087ab7ec0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
        - locked <0x0000000087ab7ec0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:158)
        at sun.java2d.Disposer.run(Disposer.java:148)
        at java.lang.Thread.run(Thread.java:745)

"Thread-0" #9 prio=5 os_prio=0 tid=0x00007f286c234800 nid=0xa4f waiting on condition [0x00007f2859af5000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at com.mycp.logging.BMBLogging$Task.run(BMBLogging.java:1072)
        at java.lang.Thread.run(Thread.java:745)

"Service Thread" #8 daemon prio=9 os_prio=0 tid=0x00007f286c0cf800 nid=0xa4d runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread2" #7 daemon prio=9 os_prio=0 tid=0x00007f286c0b2000 nid=0xa4c waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007f286c0b0000 nid=0xa4b waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007f286c0ad800 nid=0xa4a waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007f286c0ab000 nid=0xa49 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f286c07c000 nid=0xa48 in Object.wait() [0x00007f285a2dd000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000087a7e6c8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
        - locked <0x0000000087a7e6c8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:158)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)

"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f286c07a000 nid=0xa47 in Object.wait() [0x00007f285a3de000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000087a7e708> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:502)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157)
        - locked <0x0000000087a7e708> (a java.lang.ref.Reference$Lock)

"VM Thread" os_prio=0 tid=0x00007f286c072800 nid=0xa46 runnable 

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f286c01e800 nid=0xa42 runnable 

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f286c020800 nid=0xa43 runnable 

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f286c022000 nid=0xa44 runnable 

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007f286c024000 nid=0xa45 runnable 

"VM Periodic Task Thread" os_prio=0 tid=0x00007f286c0d2000 nid=0xa4e waiting on condition 

JNI global references: 485

Heap
 PSYoungGen      total 118272K, used 98176K [0x00000000d6e00000, 0x00000000de700000, 0x0000000100000000)
  eden space 113152K, 82% used [0x00000000d6e00000,0x00000000dc8e00c8,0x00000000ddc80000)
  from space 5120K, 100% used [0x00000000de180000,0x00000000de680000,0x00000000de680000)
  to   space 5120K, 0% used [0x00000000ddc80000,0x00000000ddc80000,0x00000000de180000)
 ParOldGen       total 159744K, used 76671K [0x0000000084a00000, 0x000000008e600000, 0x00000000d6e00000)
  object space 159744K, 47% used [0x0000000084a00000,0x00000000894dfc50,0x000000008e600000)
 Metaspace       used 30027K, capacity 30212K, committed 30464K, reserved 1077248K
  class space    used 3528K, capacity 3582K, committed 3584K, reserved 1048576K

线程转储显示来自大约 22 个不同线程的堆栈跟踪。其中许多看起来像应用程序线程(而不是 JVM 内部线程)。大多数应用程序线程都在等待 某事。哪些线程应该等待?

我将从查看线程 13 开始:看起来像 Swing EDT,它正在等待对按钮的 actionPerformed(...) 处理程序的调用。这可不好。

我想我迟到了。无论如何,从您的日志中我们可以看到线程处于 Parking Waiting 状态。 "TimerQueue" #22 守护进程 prio=5 os_prio=0 tid=0x00007f28002a8800 nid=0xa65 等待条件 [0x00007f284c56f000] java.lang.Thread.State:等待(停车)

我们可以看到此线程正在等待来自 DelayQueue 的内容。

DelayQueue-Delayed元素的无界阻塞队列,其中一个元素只有在其延迟期满后才能被取出。

所以在同一个TimerQueue中,我们有 在 java.util.concurrent.DelayQueue.take(DelayQueue.java:211)

如果此队列上有延迟过期的元素可用,此 take() 函数将等待。 这可能是应用程序挂起问题的原因,因为该线程仍在等待并且不会关闭。所以,仍然有线程存活。要解决此问题,您需要终止这些线程。

为此,您可以使用 ExecutorServices.shutdown() 方法。或者您可以简单地使用 System.exit()

我建议你使用 System.exit().