1 17 18 package org.apache.jasper.util; 19 20 28 public final class SimplePool { 29 30 private static final int DEFAULT_SIZE=16; 31 32 35 private Object pool[]; 36 37 private int max; 38 private int current=-1; 39 40 private Object lock; 41 42 public SimplePool() { 43 this.max=DEFAULT_SIZE; 44 this.pool=new Object [max]; 45 this.lock=new Object (); 46 } 47 48 public SimplePool(int max) { 49 this.max=max; 50 this.pool=new Object [max]; 51 this.lock=new Object (); 52 } 53 54 57 public void put(Object o) { 58 synchronized( lock ) { 59 if( current < (max-1) ) { 60 current += 1; 61 pool[current] = o; 62 } 63 } 64 } 65 66 69 public Object get() { 70 Object item = null; 71 synchronized( lock ) { 72 if( current >= 0 ) { 73 item = pool[current]; 74 current -= 1; 75 } 76 } 77 return item; 78 } 79 80 83 public int getMax() { 84 return max; 85 } 86 } 87 | Popular Tags |