Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PostOfficeQueue {
- private int tot;
- int l[];
- public PostOfficeQueue(int n){
- tot=n;
- l=new int[n];
- for(int temp:l){
- temp=0;
- }
- }
- public synchronized void deskStart(int i){
- l[i]=1;
- tot--;
- }
- public synchronized void deskFinish(int i){
- l[i]=0;
- tot--;
- notifyAll();
- }
- public synchronized int getFreeDesk(){
- while(tot==0){
- try{
- wait();
- }catch(InterruptedException e){
- return -1;
- }
- }
- int j=-1;
- for(Integer temp:l){
- j++;
- if(temp==0)return j;
- }
- return j;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement