First, the definition
Lock ReentantLock interface inheritance, he is a reentrant lock (
*
), in addition to all the work done can be synchronized, but also provided such as
in response interrupt lock
,
may poll the lock request
,
the time lock
, which avoided a multithreaded methods deadlock.
Second, the main interfaces
- void lock (): If the lock is in an idle state, the current thread to acquire the lock; otherwise, if the lock has been held by another thread, the current thread becomes disabled (blocked state) until the current thread to acquire the lock
- boolean tryLock (): If the lock is available, to acquire the lock immediately and return true; false otherwise
- void lockInterruptibly () throw InterruptedException: consistent with the lock () method, but the thread is interrupted, it throws an exception InterruptedException
- void unlock (): the current thread releases the lock held; if the thread does not hold the lock, but the implementation of this method may lead to an abnormal occurrence
- boolean isLocked (): Is there a thread
- ReentrantLock (): The default lock unfair
- ReentrantLock (boolean fair): Fair configuration lock / non-lock fair (false: unfair lock; true: Fair lock)
- Condition newCondition (): Object conditions, access to await notification component (the component and lock the current bindings)
- void await () throw InterruptedException: wait equivalence class Object () method
- void signal (): Object class equivalent notify () method
- void signalAll (): Object class equivalent notifyAll () method