File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "synchronize (this)  - what does it mean?" Watch "synchronize (this)  - what does it mean?" New topic

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,
[ 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
subject: synchronize (this) - what does it mean?
Similar Threads
Monitors wait and notifyAll
Example of wait and notify
Error in Package
DudesChat clarification please?
Why cant i call main method from another class having main block