File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: synchronize (this) - what does it mean?