Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Threads

 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
When a thread enters a synchronized method, whether that particular thread acquires the lock only for that method or the whole object in which the method is contained.

Example :


So when a thread accesses the synchronized method setValue() can any other thread access the other synchronized method getValue() ..
[ April 06, 2005: Message edited by: Srinivasa Raghavan ]
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks this example helped me.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaaaa... you're welcome?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As (I hope) you've discovered, the synchronized keyword invokes the object lock, or -- in the case of static code -- the class lock.

As of 1.5, you can use a ReentrantLock to lock specific blocks of code.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic