Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Visibility of changes  RSS feed

 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • 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?
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!