?? readwritepriority.java
字號:
package concurrency.readwrite;
//@author: j.n.magee 11/11/96
//
// The Read Write Monitor Class - Writers priority
//
class ReadWritePriority implements ReadWrite{
private int readers =0;
private boolean writing = false;
private int waitingW = 0; // no of waiting Writers.
public synchronized void acquireRead()
throws InterruptedException {
while (writing || waitingW>0) wait();
++readers;
}
public synchronized void releaseRead() {
--readers;
if (readers==0) notify();
}
public synchronized void acquireWrite()
throws InterruptedException {
++waitingW;
while (readers>0 || writing) wait();
--waitingW;
writing = true;
}
public synchronized void releaseWrite() {
writing = false;
notifyAll();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -