• 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

Visibility of changes

 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am worried because I have realized that in my program, the AWT event dispacthing thread is notifying the changes made by the user to a JList, to an object in the model: --an object in the model was implementing ListDataListener-- The problem is that the fields modified by the AWT thread are going to be read by another thread previously started. And they are not synchronized. In theory, failures in visibility of changes are very rare. Thus I guess that you do not synchronize both threads, on the same lock, just to make sure the changes made by the AWT thread are visible to the main thread, for instance. Or do you synchronize only enough while writing and reading the fields?
 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jose,

I'll stick my neck out here and say that synchronizing an object really only matters when more than one thread might modify (read then write) something. If only one thread modifies the value and other threads only read it, then I can only see that matters if the value is paired with another value that might change. In other words, there needs to be a consistent set of values at any particular time.

Ed
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic