• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating GUI from a different thread  RSS feed

 
Maysam Sorkhabi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I've read numerous times on the java tutorials that it is not wise to update GUI from threads other than the thread that the GUI is running on. I have developed applications that are multithreaded and occasioanly some of my threads update a GUI on a different thread. i.e. I initialize my working thread with the swing instance variables of the GUI thread. I indeed have noticed GUI freezes and crashes when the working thread encounters a problem or is performing a lenghty task. I am wondering what is the correct way of doing this? What the 'invokeLater' method do? How should it be used? Also what does it mean when it says component blah is "thread safe"...This is a general question so if you could just direct me to a more-concise-than-Sun's tutorial or something...Thanks so much
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use something like this.

From your other thread:


This code will be called by the GUI thread some time later.


You need to explore some thread safe ways of sharing data. You could synchronize it.

Ed
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at http://spin.sourceforge.net/ for both a good introduction and a solution to the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!