Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

THREAD LOCKS

 
sunilkumar ssuparasmul
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can somebody please explain what the following sentence means

"Locks on inner/outer objects are independent. Getting a lock on outer object doesn�t mean getting the lock on an inner object as well, that lock should be obtained separately."
Thanks in advance
sunil.s
 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Locks on inner/outer objects are independent.
Every class has a lock. This means that with respect to Inner classes, the outer class has a lock and the inner class also has a lock independent of the outer class.

Getting a lock on outer object doesn�t mean getting the lock on an inner object as well, that lock should be obtained separately
As the Outer and Inner class lock are independent of each other you have to obtain a lock for an Inner class Object if you have to access the sychronized methods of the Inner class. Acquring a lock on the Outer class Object is not sufficient to execute synchronized methods of the Inner class.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic