Threading and deadlock in Swing application

前端 未结 2 1104
清酒与你
清酒与你 2021-01-23 04:34

I\'m getting a deadlock in the Swing application I maintain, and although I have a workaround that appears to work, I\'m not sure that I have understood what I am doing and have

相关标签:
2条回答
  • 2021-01-23 05:19

    Thanks to Yishai for pointing me in the right direction. The application is instantiating its own subclass of java.awt.EventQueue and using Toolkit.getDefaultToolkit().getSystemEventQueue().push(newQueue) to replace the original queue. The original queue must still be processing a task on its thread, AWT-EventQueue-0 at the same time as events start arriving in the new queue on thread AWT-EventQueue-1, resulting in deadlock.

    0 讨论(0)
  • 2021-01-23 05:20

    Are you creating threads anywhere? If yes, consider to use

    http://docs.oracle.com/javase/7/docs/api/javax/swing/SwingWorker.html

    or

    http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html

    instead which work well with Swing.

    0 讨论(0)
提交回复
热议问题