??????????????д??
????ReentrantLock ?? ReentrantReadWriteLock
????JDK5??????ReentrantLock????????????
????1.ReentrantLock????tryLock??????tryLock?????????????????????????????????ε???tryLock???????true?????У????tryLock???????????????????false??lock()????????????
????2.????RenntrantLock?????????????boolean????????????????????????????????????????????????????????????????Ч???????Щ??????????????????Ч???????Щ??
??????????ReentrantLock?????????????unlock???????????finally??????????????£?

 

lock.lock();
try {
//do something
}
finally {
lock.unlock();
}

????ReentrantReadWriteLock??ReentrantLock???÷??????????????????readLock()??writeLock()????????????????????д????????
?????????
?????????????????????????????????jdk5?л????????????????????????????CAS?????????????????????????????????????????????????????????Ч????????????????
????AtomicInteger counter = new AtomicInteger();
????counter.incrementAndGet();
????counter.decrementAndGet();
??????????????????′?????????????????????????????????????????????????????????

 

public class CasCounter {
private SimulatedCAS value;
public int getValue() {
return value.getValue();
}
public int increment() {
int oldValue = value.getValue();
while (value.compareAndSwap(oldValue?? oldValue + 1) != oldValue)
oldValue = value.getValue();
return oldValue + 1;
}
}

?????????IBM????????????? Java ?????????: ???е????