Reentrantlock two two relatively large features.
1. Interrupts
2. Timing
3. Fair lock.
Readwritelock
Read and read not mutually exclusive
Read-Write Mutex
Write the mutex.
Condition similar to Object.wait () and object.notify () and synchronized companion use
Countdownlatch Lanchi
Synchronized
Static final Countdownlatch end = new Countdownlatch (10);
End.countdown ();
End.await ();
The Cyclicbarrier loop fence Countdownlatch can be reused.
Semaphore
Shared locks
Run multiple threads at the same time critical section
Arrayblockingqueue
Reentrantlock
+ Two X condition
/** Main Lock Guarding All access */
Final Reentrantlock lock;
/** Condition for waiting takes */
Private final Condition Notempty;
/** Condition for waiting puts */
Private final Condition Notfull;
Offer
Take
When writing. Judging condition of lock unlock
If it is full, if it is slow, wait for the notification condition of condition.
Call Insert Insert and then Notempty
Blockingqueue
public void put (e e) throws interruptedexception {
Checknotnull (e);
Final Reentrantlock lock = This.lock;
Lock.lockinterruptibly ();
try {
while (count = = items.length)
Notfull.await ();
Insert (e);
} finally {
Lock.unlock ();
}
}
private void Insert (E x) {
Items[putindex] = x;
Putindex = Inc (PUTINDEX);
++count;
Notempty.signal ();
}
Blockingqueue principle Analysis