1 package org.apache.velocity.util; 2 3 18 19 29 public final class SimplePool 30 { 31 34 private Object pool[]; 35 36 40 private int max; 41 42 46 private int current=-1; 47 48 public SimplePool(int max) 49 { 50 this.max = max; 51 pool = new Object [max]; 52 } 53 54 57 public void put(Object o) 58 { 59 int idx=-1; 60 61 synchronized( this ) 62 { 63 66 67 if( current < max - 1 ) 68 { 69 73 idx = ++current; 74 } 75 76 if( idx >= 0 ) 77 { 78 pool[idx] = o; 79 } 80 } 81 } 82 83 86 public Object get() 87 { 88 int idx = -1; 89 90 synchronized( this ) 91 { 92 95 if( current >= 0 ) 96 { 97 103 104 idx = current; 105 current--; 106 107 112 113 return pool[idx]; 114 } 115 } 116 117 return null; 118 } 119 120 122 public int getMax() 123 { 124 return max; 125 } 126 } 127 | Popular Tags |