1 9 package javolution.realtime; 10 11 import javolution.JavolutionError; 12 13 24 public abstract class ObjectPool { 25 26 29 public static final ObjectPool NULL = new ObjectPool() { 30 public Object next() { 31 return null; 32 } 33 public void recycle(Object obj) {} 34 protected void recycleAll() {} 35 protected void clearAll() {} 36 }; 37 38 39 42 ObjectPool outer; 43 44 47 Thread user; 48 49 52 boolean inUse; 53 54 57 protected ObjectPool() { 58 } 59 60 65 public final Thread getUser() { 66 return user; 67 } 68 69 81 public final boolean isLocal() { 82 if (inUse) { 83 if (user == null) { 84 return false; } else { 86 if (user == Thread.currentThread()) { 87 return true; } else { 89 throw new JavolutionError( 90 "Concurrent access to local pool detected"); 91 } 92 } 93 } else { 94 throw new JavolutionError( 95 "Access to inner pool or unused pool detected"); 96 } 97 } 98 99 107 public final boolean inUse() { 108 return inUse; 109 } 110 111 116 public final ObjectPool getOuter() { 117 return outer; 118 } 119 120 127 public abstract Object next(); 128 129 137 public abstract void recycle(Object obj); 138 139 143 149 protected abstract void recycleAll(); 150 151 157 protected abstract void clearAll(); 158 159 } | Popular Tags |