ReentranLock and Usage Analysis

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
  1. 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
  2. boolean tryLock (): If the lock is available, to acquire the lock immediately and return true; false otherwise
  3. void lockInterruptibly () throw InterruptedException: consistent with the lock () method, but the thread is interrupted, it throws an exception InterruptedException
  4. 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
  5. boolean isLocked (): Is there a thread
  6. ReentrantLock (): The default lock unfair
  7. ReentrantLock (boolean fair): Fair configuration lock / non-lock fair (false: unfair lock; true: Fair lock)
  8. 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

 

Guess you like

Origin www.cnblogs.com/pascall/p/11121428.html