/** * Checks out an object from the pool. Creates a new one if the pool is * empty. * * @return An object from the pool. */ public T checkout() { T result; if ((result = this.store.poll()) == null) { result = createObject(); } return result; }
/** * Pre-creates the initial objects using the {@link #createObject()} method * and check them in the pool using the {@link #checkin(Object)} method. * * @param initialSize * The initial number of objects. */ public void preCreate(int initialSize) { for (int i = 0; i < initialSize; i++) { checkin(createObject()); } }