InterviewSolution
| 1. |
Why Is It Named Reentrantlock? |
|
Answer» It is called ReentrantLock as there is an acquisition count associated with the lock which MEANS when you use lock() method to acquire a lock and you get it then the acquisition count is 1. A REENTRANT lock will ALSO allow the lock holder to enter another block of CODE with the same lock object as thread already owned it. In that case, if a thread that holds the lock acquires it again, the acquisition count is incremented and the lock then needs to be released twice to TRULY release the lock. It is called ReentrantLock as there is an acquisition count associated with the lock which means when you use lock() method to acquire a lock and you get it then the acquisition count is 1. A Reentrant lock will also allow the lock holder to enter another block of code with the same lock object as thread already owned it. In that case, if a thread that holds the lock acquires it again, the acquisition count is incremented and the lock then needs to be released twice to truly release the lock. |
|