Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads: Doubt

 
dedcat achi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain this:

"A thread can acquire more than one lock. For example, a thread can enter a synchronized method, thus acquiring a lock, and then immediately invoke a synchronized method on a different object, thus acquiring that lock as well. Also, if a thread acquires a lock and then attempts to call a synchronized method on the same object, no problem."

Can you please give an example this to explain the above statements.

Thanks!
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example



The lock of this object, System.out is obtained. Another synchronized method is called from the body of the synchronized block
 
dedcat achi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great!
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic