• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

synchronize (this) - what does it mean?

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What’s the effect of synchronize on thread?
 
Ranch Hand
Posts: 62
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic