• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing threading model

 
m asif
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we know swing is effectively single-threaded. We use invokeLater/InvokeAndWait methods if we have separate worker thread for GUI-related processing.
Runnable doWork=new Runnable() { public void run(){ javax.swing.JOptionPane.showMessageDialog(WelcomeApp.frame,"Hello there"); } }; javax.swing.SwingUtilities.invokeLater(doWork);
Above code post data into eventDispatching thread. Right?
I tried to check the Swing behavior without using invokeLater method, but the following code also yield the same result. Why?
class testSwingThread extends Thread { public void run(){ javax.swing.JOptionPane.showMessageDialog(WelcomeApp.frame,"Hello there from Other thread"); } } testSwingThread tst=new testSwingThread(); tst.start();
Thanks in advance!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out this Swing Connection article on threading in Swing.

The issue isn't that methods won't work when called from another thread... it's that they can get out of order or corrupted if multiple threads attempt to make method calls to the same object.
 
m asif
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nathan Pruett! I got the perfect answer what I am looking for
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!