This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Why synchronization here? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Why synchronization here?" Watch "Why synchronization here?" New topic

Why synchronization here?

Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 434
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.

To be or not to be. It's a question.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
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...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Why synchronization here?
It's not a secret anymore!