Discussion:
JDialog.dispose() blocking forever
(too old to reply)
Richard Huddleston
2003-10-22 01:05:08 UTC
Permalink
i have one thread process actionevents, then start another thread execute
code like "get user input" in a JOptionPane.showInputDialog. when i click
ok/cancel whatever the dialog closes, but the method from JOptionPane never
returns.

I thought this could just be a JOptionPane bug, but I re-implemented the
with a custom Dialog, the same bug. Doing thread analysis i get this for
the thread which is waiting for the Dialog to be closed.

"ThreadX" prio=10 tid=0x184c4688 nid=0x658 in Object.wait()
[209ff000..209ffd90]
at java.lang.Object.wait(Native Method)
- waiting on <0x1004e1e0> (a java.awt.EventQueue$1AWTInvocationLock)
at java.lang.Object.wait(Unknown Source)
at java.awt.EventQueue.invokeAndWait(Unknown Source)
- locked <0x1004e1e0> (a java.awt.EventQueue$1AWTInvocationLock)
at java.awt.Window.dispose(Unknown Source)
at java.awt.Dialog.disposeImpl(Unknown Source)
at java.awt.Dialog.dispose(Unknown Source)
at javax.swing.JOptionPane.showInputDialog(Unknown Source)
at javax.swing.JOptionPane.showInputDialog(Unknown Source)
at javax.swing.JOptionPane.showInputDialog(Unknown Source)
at castles.gui.CastleGameApp.newGame(CastleGameApp.java:181)
- locked <0x105397b8> (a castles.gui.CastleGameApp)
at castles.gui.CastleGameApp.actionPerformed(CastleGameApp.java:136)
at castles.gui.ActionEventThread.run(ActionEventThread.java:34)

Also, my entire GUI stops re-drawing.

Any help would be apprecated.

Richard
Filip Larsen
2003-10-22 07:32:55 UTC
Permalink
Post by Richard Huddleston
i have one thread process actionevents, then start another thread execute
code like "get user input" in a JOptionPane.showInputDialog. when i click
ok/cancel whatever the dialog closes, but the method from JOptionPane never
returns.
As a rule of thumb, never assume that calls to Swing or AWT components can
be done from outside the AWT event dispatcher thread unless explicitly
stated so in the documentation. To my knowledge, there are only a few calls
that are "thread-safe" in this respect. For the rest, the
SwingUtilities.invokeLater and .invokeAndWait methods can be used to perform
GUI work from other threads. In your case it sound like invokeAndWait might
be useful.


Regards,
--
Filip Larsen
Loading...