From what I have read, synchronized
block of code means intrinsic re-entrant lock of an object, and ReentrantLock
is an abstraction to achieve re-entrance. Is there a need to use ReentrantLock
other than calling lock()
and unlock()
methods from different methods, pieces of codes?
Documentation of ReentrantLock
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.
Those extended capabilities are related to the monitoring of the synchronization, as well as customization of the behavior. Looking at the method list should speak for itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.