wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes synchronize (this)  - what does it mean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "synchronize (this)  - what does it mean?" Watch "synchronize (this)  - what does it mean?" New topic
Author

synchronize (this) - what does it mean?

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
What’s the effect of synchronize on thread?
Marcos R Oliveira
Ranch Hand

Joined: Apr 20, 2002
Posts: 51
Hi, Thomas.
Synchronized prevents one thread from printing the messages while the other is still doing it. Take off the synchronized and run and you�ll see the mess.
When the running threads get to the point where the synchronized block is, it mustget the lock to this object before getting into it. If the lock belongs to the other thread, it will wait untill the lock is available again.
Hope I have answered your question,
Marcos.
[ November 08, 2002: Message edited by: Marcos R Oliveira ]
[ November 08, 2002: Message edited by: Marcos R Oliveira ]

SCJP 1.4 - SCJP 1.6 - SCWCD in progress
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: synchronize (this) - what does it mean?
 
Similar Threads
Why cant i call main method from another class having main block
Example of wait and notify
DudesChat clarification please?
Error in Package
Monitors wait and notifyAll