• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threading  RSS feed

 
Mark Do
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HOW does threading prevent GUI unresponsiveness?

Thanks!
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
User interfaces are constantly being drawn and redrawn. This happens on the Event Dispatch Thread (EDT). If you are writing a GUI, then your code will be run by default on the EDT.
However, what if your program must perform a time consuming operation when some button is pressed? Unless you do something about it, this time consuming operation will be run on the EDT, the same thread that is trying to continuously redraw the GUI.
Therefore, unless you place your time consuming operation on a different thread (via a SwingWorker), your GUI will not be redrawn until the completion of your long task.
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that it has not yet proven possible to write a threadsafe GUI framework. So be sure to run all your GUI code in the EDT except things which take a long time where SwingWorker works nicely, as JC has already told you.

I shall move this discussion to our GUIs forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!