أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities.
Synchronized uses intrinsic locks or monitors.
An intrinsic locking mechanism can have some functional limitations, such as:
1.) It is not possible to interrupt a thread waiting to acquire a lock (lock Interruptibly).
2.) It is not possible to attempt to acquire a lock without being willing to wait for it forever (try lock).
3.) Cannot implement non-block-structured locking disciplines, as intrinsic locks must be released in the same block in which they are acquired.
A ReentrantLock is owned by the thread last successfully locking, but not yet unlocking it. A thread invoking lock will return, successfully acquiring the lock, when the lock is not owned by another thread. The method will return immediately if the current thread already owns the lock. This can be checked using methods isHeldByCurrentThread(), and getHoldCount().