ReentrantLock

An explicit lock from java.util.concurrent.locks that a thread may acquire more than once.

In more detail

Call lock() before a try block and unlock() in its finally block. Each lock() adds to a hold count, and the lock is free only when unlock() has been called as often. tryLock() returns false at once instead of waiting, and unlocking a lock you do not hold throws IllegalMonitorStateException.

Example

lock.lock();
try { count++; } finally { lock.unlock(); }

Related terms

Taught in

References

Certification courses