Unresponsive threading involving Swing and AWT-EventQueue

后端 未结 8 790
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 09:00

I have an application that is unresponsive and seems to be in a deadlock or something like a deadlock. See the two threads below. Notice that the My-Thread@101c

8条回答
  •  醉酒成梦
    2020-12-05 09:20

    It's hard to tell without seeing the code, but from the stack trace, it looks like you're firing some sort of transactional code from the event dispatch thread. Does that code then kick off an instance of My-Thread? The EDT could be blocked waiting for My-Thread from within the transactional code, but My-Thread can't finish because it needs the EDT.

    If this is the case, you can use SwingUtilities.invokeLater for your rendering so the EDT finishes the transactional code and then it will render the updates. Or, you can not perform the transactional code from the EDT. For actual work that's not related to rendering, you should use a SwingWorker to avoid doing any heavy processing on the EDT.

提交回复
热议问题