?? datapool.java
字號:
package mmscenter;import java.util.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author rjz * @version 1.0 */public class DataPool { private Vector pipe; private int capacity; private int size; public boolean has_elements=false; public DataPool() { pipe=new Vector(); this.size=0; this.capacity=100; } public DataPool(int capacity){ pipe=new Vector(); this.capacity=capacity; this.size=0; } public int getSize(){ return this.size; } public boolean isFull(){ if (this.capacity>this.size) return false; else return true; } public boolean isEmpty(){ if (this.size==0) return true; else return false; } public synchronized boolean push(Object o){/* while(this.size==this.capacity){ try{ wait(); }catch(Exception e){ e.printStackTrace(); } } this.pipe.addElement(o); this.size++; try{ notifyAll(); }catch(Exception e){ e.printStackTrace(); } //this.has_elements=true; return true;*/ if (this.size<this.capacity){ this.pipe.addElement(o); this.size++; return true; }else{ return false; } } public synchronized Object pop(){ //System.out.println("===========pop=========="); //if (this.has_elements){/* 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; if (this.size>0){ result=this.pipe.remove(0); this.size--; } try{ notifyAll(); }catch(Exception e){ e.printStackTrace(); } return result;*/ Object result=null; if (this.size>0){ result=this.pipe.get(0); this.pipe.remove(0); this.size--; } return result; } public void release(){ this.pipe.removeAllElements(); this.pipe=null; } public static void main(String[] args) { // DataPool dataPool1 = new DataPool(); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -