Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Updating GUI from a different thread

Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
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.

Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at for both a good introduction and a solution to the problem.
I am Arthur, King of the Britons. And this is a tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic