比如如下代碼,降級(jí)了并沒有并發(fā)執(zhí)行啊? public void put(Object data){
rwl.writeLock().lock();
rwl.readLock().lock();
System.out.println(Thread.currentThread().getName() + " be ready to write data!");
try {
Thread.sleep((long)(Math.random()*1000));
} catch (InterruptedException e) {
e.printStackTrace();
}
this.data = data;
System.out.println(Thread.currentThread().getName() + " have write data: " + data);
rwl.readLock().unlock();
rwl.writeLock().unlock();
}輸出:Thread-0 be ready to write data!Thread-0 have write data: 1103Thread-2 be ready to write data!Thread-2 have write data: 4531Thread-1 be ready to write data!Thread-1 have write data: 2188也并沒有并發(fā)執(zhí)行啊
讀寫鎖ReentrantReadWriteLock鎖降級(jí)的意義是什么啊
三國(guó)紛爭(zhēng)
2018-07-24 11:14:31