1 23 package com.sun.enterprise.util; 24 25 30 31 public abstract class PoolBase implements Pool { 32 33 private final Semaphore available_; 34 private int numItems_; 35 36 protected PoolBase(int numItems) { 37 numItems_ = numItems; 38 available_ = new SemaphoreImpl(numItems); 39 } 40 41 public void initialize() throws Exception { 42 doInitializeItems(numItems_); 43 } 44 45 public Object getItem() throws InterruptedException { 46 available_.acquire(); 47 return doGet(); 48 } 49 50 public void returnItem(Object o) { 51 if( doReturn(o) ) { 52 available_.release(); 53 } 54 } 55 56 protected abstract Object doGet(); 57 protected abstract boolean doReturn(Object object); 58 protected abstract void doInitializeItems(int numItems) throws Exception ; 59 60 } 61 | Popular Tags |