I am learning about Reentrant Lock in
Java. I have certain queries related to this:
1. In Reentrant Locks, we can call lock() method multiple times and then need to call unlock() method same number of times. I am unable to understand if I call the lock() method first, I have got the lock, then what is the use of calling lock() method again?
2. In synchroinzed block/methods, we get the lock on object/class depending upon the object. But, in case of Lock API, when we say that we have got the lock, then what is this lock actually?
3. In Reentrant Lock, we have tryLock() method, so, if it gets the lock by calling tryLock(), then it would enter that piece of code, otherwise, will continue with other piece of execution. I am just wondering if I need to continue with other piece of code, then why would I need to the lock at first place itself?
Please share your inputs.