package Exp1;
import java.util.LinkedList;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class createQueue {
int max=5;
LinkedList<Integer> Queue=new LinkedList<Integer>();
Lock lock=new ReentrantLock();
Condition empty=lock.newCondition();
Condition full=lock.newCondition();
public synchronized void push(int ProdRandom){
	try{
		lock.lock();
		while(max==Queue.size()){
	System.out.println("存储空间已满,请等待");
	full.await();
		}
		Queue.add(ProdRandom);
		empty.signal();
	}
		catch(InterruptedException e){
			e.printStackTrace();
		}
	finally{
		lock.unlock();
	}
}
@SuppressWarnings("finally")
public synchronized int pop(){
	int m=0;
	try{
		lock.lock();
	while(Queue.size()==0){
		System.out.println("存储空间已空,请等待");
		empty.await();
	}
	m=Queue.removeFirst();
	full.signal();
	}
		catch(InterruptedException e){
			e.printStackTrace();
		}
	finally{
		lock.unlock();
		return m;
	}
}
}
最近下载更多
                
最近浏览更多
                
                阿超在大学修仙     LV1
                2023年9月15日
            
            
        
                caomin     LV4
                2023年5月25日
            
            
        
                wuziayng1232     LV11
                2023年2月21日
            
            
        
                3043864991     LV2
                2023年1月5日
            
            
        
                jjfskldjf     LV2
                2022年11月27日
            
            
        
                微信网友_6191697646571520     LV6
                2022年11月23日
            
            
        
                shibing333     LV1
                2022年10月10日
            
            
        
                18214966423     LV2
                2022年9月6日
            
            
        
                陈小灏     LV18
                2022年6月8日
            
            
        
                Tiam123     LV3
                2021年12月22日
            
            
        
    
                
                