?? boundedovertakingallocator.java
字號:
//********************************************************
//
// BoundedOvertakingAllocator Class
//
package concurrency.golf;
public class BoundedOvertakingAllocator implements Allocator{
private int available;
private int turn = 0;
private int next = 0;
private int bound;
private int overtaken =0;
public BoundedOvertakingAllocator(int n, int b)
{ available = n; bound = b;}
synchronized public void get(int n)
throws InterruptedException{
int myturn = turn; ++turn;
boolean overtakenMe = false;
while (n>available || (overtaken>0 && !overtakenMe)) {
wait();
if ((next>= (myturn + bound)) && !overtakenMe) {
overtakenMe = true; ++overtaken;
}
}
if (overtakenMe) --overtaken;
++next; available -= n;
notifyAll();
}
synchronized public void put(int n) {
available += n;
notifyAll();
}
}
//********************************************************
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -