예제 #1
0
 /**
  * Retrieves the first available object in the pool or returns null if none are available.
  *
  * @return T
  * @throws Exception
  */
 public T request() throws Exception {
   T t = queue.poll();
   if (t != null) {
     if (generator != null) generator.enable(t);
   }
   return t;
 }
예제 #2
0
 /**
  * Retrieves the first available object in the pool or creates a new instance if there are none
  * available.
  *
  * @return T
  */
 public T get() {
   T t = queue.poll();
   if (t == null) {
     t = newInstance();
   }
   if (generator != null) generator.enable(t);
   return t;
 }
예제 #3
0
 protected T newInstance() {
   T t = null;
   if (generator != null) {
     t = generator.newInstance();
   } else if (c != null) {
     try {
       t = c.newInstance();
     } catch (Exception exc) {
       throw new RuntimeException("Unable to instantiate Class: " + c.getCanonicalName(), exc);
     }
   }
   if (t != null) total++;
   return t;
 }
예제 #4
0
 /**
  * Releases the object back into the pool for re-use.
  *
  * @param t
  * @return boolean
  */
 public boolean release(T t) {
   if (generator != null) generator.disable(t);
   return queue.offer(t);
 }