waitqueue.java

来自「RFID复杂事件处理系统的研究实验」· Java 代码 · 共 47 行

JAVA
47
字号
package test2;

import java.util.LinkedList;

public class WaitQueue implements EventReceiver{
	
	private LinkedList<P_Event> queue=new LinkedList<P_Event>();

	
	WaitQueue(){}
	

	public synchronized void acceptEvent(P_Event e)
	{
		queue.addLast(e);
		
		this.notify();
	}
	
	public synchronized P_Event getEvent()
	{
		try
		{
			if(queue.size()==0) 
			{
				this.wait();
			}			
		}
	    catch (InterruptedException e)
	    {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
	    }
	    return queue.removeFirst();
	}

	
	public int getsize()
	{
		return queue.size();
	}
	public LinkedList<P_Event> getQueue() {
		return queue;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?