📄 datapool.java
字号:
package orderapp;/** * Title: * Description: * 数据池父类,数据同步 * Copyright: Copyright (c) 2002 * Company: * @author * @version 1.0 */import java.util.*;public class DataPool{ public int size=0; public int capacity=0; public Vector pipe; public boolean has_Elements; public DataPool(int capacity){ size=0; pipe=new Vector(); has_Elements=false; this.capacity=capacity; } public DataPool(){ size=0; capacity=100; pipe=new Vector(); has_Elements=false; } public int getSize(){ return size; } public boolean isFull(){ return capacity<=size; } public boolean isEmpty(){ return size==0; } public synchronized boolean push(Object o){ while(this.size==capacity){ try{ wait(); } catch(Exception e){ e.printStackTrace(); } } pipe.addElement(o); size++; try{ notifyAll(); } catch(Exception e){ e.printStackTrace(); } return true; } public synchronized Object pop(){ while(this.size<0){ try{ //if(this.has_elements){ //System.out.println("wait"); wait(); //System.out.println("wake"); //} }catch(Exception e){ e.printStackTrace(); } } Object result=null; result=pipe.get(0); pipe.remove(0); size--; try{ notifyAll(); } catch(Exception e){ e.printStackTrace(); } return result; } public void release(){ pipe.removeAllElements(); pipe=null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -