1 21 22 package org.webdocwf.util.loader.generator; 23 24 import java.util.*; 25 26 33 public class BufferClass { 34 35 static private BufferClass instance; 36 private ArrayList buffer; 37 private static boolean isUsed=false; 38 39 44 static public BufferClass getInstance() { 45 if (instance == null) { 46 instance = new BufferClass(); 47 } 48 return instance; 49 } 50 51 54 private BufferClass() { 55 init(); 56 } 57 58 61 private void init(){ 62 buffer=new ArrayList(); 63 } 64 65 69 public synchronized void writeToBuffer(String msg){ 70 if(isUsed==true){ 71 buffer.add(0,msg); 72 notify(); 73 } 74 } 75 76 80 public synchronized String readFromBuffer(){ 81 if(buffer.isEmpty()){ 82 try{ 83 wait(); 84 }catch(Exception ex){ 85 } 87 } 88 String ret=(String ) buffer.remove(buffer.size()-1); 89 notify(); 90 return ret; 91 } 92 93 97 public boolean IsUsed(){ 98 return isUsed; 99 } 100 101 104 public void empty () { 105 buffer.clear(); 106 } 107 108 111 public void setUsed(){ 112 isUsed=true; 113 } 114 } | Popular Tags |