Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Understanding contention examples in developerWorks article  RSS feed

 
HanMing Low
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'd appreciate if anyone can help to explain to me why if a thread is executing setUserInfo in the following code will locked out thread of getServiceInfo and setServiceInfo as well.

As explained in an article in
http://www-106.ibm.com/developerworks/java/library/j-threads2.html
Technique 2 : Reducing lock granularity
I appreciate any advice.
Cheers.

Han Ming
 
Thomas Thomas
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
u cannot run two synchronized methods of the same object at a time bcz the lock is given by the object and it has only one lock.
if u r using a complex method in which a small part is to be synchronized .u can synchronized blocks
synchronized(this/object){
}
I hope i didn't misunderstand u r question.
thomas
 
HanMing Low
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the reply.
That answers my question.

Cheers.

Han Ming
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!