• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread-Safe issues

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know most Swing components are not thread-safe, but does this mean I shouldn't even call getHeight() or isVisible() from anything but the Event Dispatch Thread (i.e. methods that do not modify the component)? The JavaDocs state (not quoted verbatim) that methods and components that are thread-safe are specifically stated as so, but get and is methods never mention either way.

Thanks,

Andy
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't call them outside the EDT if you're doing something that "depends on that state" - there's no guarantee of ordering. So the EDT thread could be updating the height of a component, and your thread reads it at the same time - there's no guarantee that you're going to get the old height value or the updated height value.

If you're doing something like just polling and printing out the values this isn't much of an issue.

If it's something like "if the component is visible, then perform some steps that require the component to be visible" - then you can't assume that the result of the if(component.isVisible()) is completely accurate - another thread may call component.setVisible(false) while you're in the middle of calling isVisible() or during the processing afterward.
 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic