Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why synchronization here?

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading Concurrent Programming in Java, and getting confused about the fist example.

After looking through the code. I don't find any possibilities that multi-threads invoke methods or get/update attributes on the same object. Why synchronization is added? Why add synchronization to Applet's start() and stop() methods? Would you help me to clarify this? Thanks.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The move and draw methods of the particles need to be synchronized because they are working on the same data, and are called from different threads - move from the thread of the particle, draw from the AWT event dispatch thread.

For the other synchronized code, I'm as confused as you are...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic