Borrow an object from the pool
@return a pooled object
193685
public synchronized T borrow() throws JMSException
	{
		if (closed)
			throw new ObjectPoolException("Object pool is closed");
		
		// Object immediately available ?
		int availableCount = available.size();
		if (availableCount > 0)
			return available.remove(availableCount-1);
		
		// Can we create one more ?
		if (all.size() < maxSize)
			return extendPool();
		
		// Pool is exhausted
		switch (exhaustionPolicy)
		{
			case WHEN_EXHAUSTED_FAIL  : throw new ObjectPoolException("Pool is exhausted (maxSize="+maxSize+")");
			case WHEN_EXHAUSTED_BLOCK : return waitForAvailability();
			case WHEN_EXHAUSTED_WAIT  : return waitForAvailability(waitTimeout,true);
			case WHEN_EXHAUSTED_RETURN_NULL : return null;
			case WHEN_EXHAUSTED_WAIT_RETURN_NULL : return waitForAvailability(waitTimeout,false);
			
			default:
				throw new ObjectPoolException("Invalid exhaustion policy : "+exhaustionPolicy);
		}
	}
178269
public IRedisClient getRedisClient(final String host, final int port, final String username,
            final String password, final PoolConfig poolConfig) {
        String poolName = calcRedisPoolName(host, port, username, password, poolConfig);

        try {
            JedisClientPool redisClientPool = cacheRedisClientPools.get(poolName,
                    new Callable<JedisClientPool>() {
                        @Override
                        public JedisClientPool call() throws Exception {
                            return createRedisClientPool(host, port, username, password, poolConfig);
                        }
                    });
            return redisClientPool.borrowObject();
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            return null;
        }
    }
248560
public PersistenceBrokerInternal createPersistenceBroker(PBKey pbKey) throws PBFactoryException
    {
        if (log.isDebugEnabled()) log.debug("Obtain broker from pool, used PBKey is " + pbKey);
        PersistenceBrokerInternal broker = null;

        /*
        try to find a valid PBKey, if given key does not full match
        */
        pbKey = BrokerHelper.crossCheckPBKey(pbKey);

        try
        {
            /*
            get a pooled PB instance, the pool is reponsible to create new
            PB instances if not found in pool
            */
            broker = ((PersistenceBrokerInternal) brokerPool.borrowObject(pbKey));
            /*
            now warp pooled PB instance with a handle to avoid PB corruption
            of closed PB instances.
            */
            broker = wrapRequestedBrokerInstance(broker);

        }
        catch (Exception e)
        {
            try
            {
                // if something going wrong, tryto close broker
                if(broker != null) broker.close();
            }
            catch (Exception ignore)
            {
                //ignore it
            }
            throw new PBFactoryException("Borrow broker from pool failed, using PBKey " + pbKey, e);
        }
        return broker;
    }
1339093
public synchronized List getList() {
        if (tc.isEntryEnabled())
            SibTr.entry(tc, "getList");

        // Remove a List from the pool
        List list = (List) listPool.remove();

        // If the list is null then there was none available in the pool
        // So create a new one
        if (list == null) {
            if (tc.isDebugEnabled())
                SibTr.debug(tc, "No list available from pool - creating a new one");

            // We could change the list implementation here if we wanted         
            list = new ArrayList(5);
        }

        if (tc.isEntryEnabled())
            SibTr.exit(tc, "getList");

        return list;
    }
1092478
@Override
    public final T get() {
        if (obj == null) {
            synchronized (lock) {
                if (obj == null) {
                    obj = create();
                }
            }
        }
        return obj;
    }
1320441
public PooledObject<T> get() {
        T data = pool.pollLast();
        if (data == null) {
            data = function.get();
        }

        return new PooledObjectImpl<>(data, pool);
    }
1369550
public synchronized Object getInstanceIfFree()
  {

    // Check if the pool is empty.
    if (!freeStack.isEmpty())
    {

      // Remove object from end of free pool.
      Object result = freeStack.remove(freeStack.size() - 1);
      return result;
    }

    return null;
  }
676418
@Override
    public Object get() {

        Object oObject = null;

        synchronized (this) {
            // Check if any are free in the free hashtable
            if (lastEntry > -1) {
                // Free array has entries, get the last one.
                // remove last one for best performance
                oObject = free[lastEntry];
                free[lastEntry] = null;
                if (lastEntry == firstEntry) { // none left in pool
                    lastEntry = -1;
                    firstEntry = -1;
                } else if (lastEntry > 0) {
                    lastEntry = lastEntry - 1;
                } else { // last entry = 0, reset to end of list
                    lastEntry = poolSize - 1;
                }
            }
        }
        if (oObject == null && factory != null) {
            oObject = factory.create();
        }

        return oObject;
    }
628419
public E borrowObject() throws Exception
    {
        assertOpen();
        long starttime = System.currentTimeMillis();
        for (; ;)
        {

            E obj = null;

            // if there are any sleeping, just grab one of those
            synchronized (this)
            {
                obj = pool.remove();

                // otherwise
                if (null == obj)
                {
                    // check if we can create one
                    // (note we know that the num sleeping is 0, else we wouldn't be here)
                    if (maxActive < 0 || numActive < maxActive)
                    {
                        // allow new object to be created
                    }
                    else
                    {
                        // the pool is exhausted
                        switch (whenExhaustedAction)
                        {
                            case WHEN_EXHAUSTED_GROW:
                                // allow new object to be created
                                break;
                            case WHEN_EXHAUSTED_FAIL:
                                throw new NoSuchElementException("Pool exhausted");
                            case WHEN_EXHAUSTED_BLOCK:
                                try
                                {
                                    if (maxWait <= 0)
                                    {
                                        wait();
                                    }
                                    else
                                    {
                                        // this code may be executed again after a notify then continue cycle
                                        // so, need to calculate the amount of time to wait
                                        final long elapsed = (System.currentTimeMillis() - starttime);
                                        final long waitTime = maxWait - elapsed;
                                        if (waitTime > 0)
                                        {
                                            wait(waitTime);
                                        }
                                    }
                                }
                                catch (InterruptedException e)
                                {
                                    Thread.currentThread().interrupt();
                                    throw e;
                                }
                                if (maxWait > 0 && ((System.currentTimeMillis() - starttime) >= maxWait))
                                {
                                    throw new NoSuchElementException("Timeout waiting for idle object");
                                }
                                else
                                {
                                    continue; // keep looping
                                }
                            default:
                                throw new IllegalArgumentException("WhenExhaustedAction property " + whenExhaustedAction + " not recognized.");
                        }
                    }
                }
                numActive++;
            }

            // create new object when needed
            boolean newlyCreated = false;
            if (null == obj)
            {
                try
                {
                    obj = factory.makeObject(this);
                    newlyCreated = true;
                    return obj;
                }
                finally
                {
                    if (!newlyCreated)
                    {
                        // object cannot be created
                        synchronized (this)
                        {
                            numActive--;
                            notifyAll();
                        }
                    }
                }
            }

            // activate & validate the object
            try
            {
                factory.activateObject(obj);
                if (testOnBorrow && !factory.validateObject(obj))
                {
                    throw new Exception("ValidateObject failed");
                }
                return obj;
            }
            catch (Throwable e)
            {
                reportException("object activation or validation failed ", e);
                synchronized (this)
                {
                    // object cannot be activated or is invalid
                    numActive--;
                    notifyAll();
                }
                destroyObject(obj);
                if (newlyCreated)
                {
                    throw new NoSuchElementException("Could not create a validated object, cause: " + e.getMessage());
                }
                // keep looping
            }
        }
    }
1152747
private PoolEntry createPoolEntry()
   {
      try {
         final PoolEntry poolEntry = newPoolEntry();

         final long maxLifetime = config.getMaxLifetime();
         if (maxLifetime > 0) {
            // variance up to 2.5% of the maxlifetime
            final long variance = maxLifetime > 10_000 ? ThreadLocalRandom.current().nextLong( maxLifetime / 40 ) : 0;
            final long lifetime = maxLifetime - variance;
            poolEntry.setFutureEol(houseKeepingExecutorService.schedule(
               () -> {
                  if (softEvictConnection(poolEntry, "(connection has passed maxLifetime)", false /* not owner */)) {
                     addBagItem(connectionBag.getWaitingThreadCount());
                  }
               },
               lifetime, MILLISECONDS));
         }

         return poolEntry;
      }
      catch (ConnectionSetupException e) {
         if (poolState == POOL_NORMAL) { // we check POOL_NORMAL to avoid a flood of messages if shutdown() is running concurrently
            logger.error("{} - Error thrown while acquiring connection from data source", poolName, e.getCause());
            lastConnectionFailure.set(e);
         }
         return null;
      }
      catch (SQLException e) {
         if (poolState == POOL_NORMAL) { // we check POOL_NORMAL to avoid a flood of messages if shutdown() is running concurrently
            logger.debug("{} - Cannot acquire connection from data source", poolName, e);
            lastConnectionFailure.set(new ConnectionSetupException(e));
         }
         return null;
      }
      catch (Exception e) {
         if (poolState == POOL_NORMAL) { // we check POOL_NORMAL to avoid a flood of messages if shutdown() is running concurrently
            logger.error("{} - Error thrown while acquiring connection from data source", poolName, e);
            lastConnectionFailure.set(new ConnectionSetupException(e));
         }
         return null;
      }
   }
309463
@Override
    public Connection makeObject(ObjectPoolWithThreadAffinity<Connection> pool) throws Exception
    {
        Connection conn = connectionFactory.createConnection();
        return new PooledConnection(conn, pool, this.statementsToPool);
    }
641425
@Override
    public DiskSpoolEventWriter get()
    {
        return new DiskSpoolEventWriter(new EventHandler()
        {
            @Override
            public void handle(final File file, final CallbackHandler handler)
            {
                eventSender.send(file, handler);
            }
        }, config.getSpoolDirectoryName(), config.isFlushEnabled(), config.getFlushIntervalInSeconds(), executor,
            SyncType.valueOf(config.getSyncType()), config.getSyncBatchSize(), new NoCompressionCodec(), serializer);
    }
28102
private LocalThreadObjectPool getThreadLocalObjectPool() {
        if (threadPoolSize <= 0) {
            // no local thread pool needed.
            return null;
        }
        LocalThreadObjectPool localPool = null;
        if (threadLocals != null) {
            localPool = threadLocals.get();
            if (localPool == null) {
                localPool = new LocalThreadObjectPool(threadPoolSize, null, destroyer); // @PK36998C
                threadLocals.set(localPool);

                localPool.setCleanUpOld(cleanUpOld);
            }
        }

        return localPool;
    }
969894
public ObjectPool createConnectionPool(JdbcConnectionDescriptor jcd)
    {
        if (log.isDebugEnabled()) log.debug("createPool was called");
        PoolableObjectFactory pof = new ConPoolFactory(this, jcd);
        GenericObjectPool.Config conf = jcd.getConnectionPoolDescriptor().getObjectPoolConfig();
        return (ObjectPool)new GenericObjectPool(pof, conf);
    }
633408
private function _getRequestPool(): Pool
    {
        return new Pool($this->_getClient(), $this->_getRequestPromise(), [
            'concurrency' => max(1, $this->configOfConcurrency),
            'fulfilled' => function () {
                call_user_func_array([$this, '_responseSuccessHandle'], func_get_args());
            },
            'rejected' => function () {
                call_user_func_array([$this, '_responseFailHandle'], func_get_args());
            }
        ]);
    }
846874
public synchronized DTMIterator getInstance()
  {
    // Check if the pool is empty.
    if (m_freeStack.isEmpty())
    {

      // Create a new object if so.
      try
      {
        return (DTMIterator)m_orig.clone();
      }
      catch (Exception ex)
      {
        throw new WrappedRuntimeException(ex);
      }
    }
    else
    {
      // Remove object from end of free pool.
      DTMIterator result = (DTMIterator)m_freeStack.remove(m_freeStack.size() - 1);
      return result;
    }
  }
997370
public boolean put(T object) {
        if (object == null) {
            throw new IllegalArgumentException("returning null object to pool");
        }

        while (true) {
            // 1. get the index of the next free cell
            int g = m_get.get();
            int p = m_put.get();
            if (p >= LIMIT) {
                // this happens very seldom - once every 1**31 calls, the put
                // index completes a full cycle.
                // to handle this simply, we just wait for the pool to
                // drain, and start placing objects back in the pool only when
                // the get index completes its cycle too.
                return false;
            }
            if (p - g >= (m_arraySize - 1)) {
                // put index is far from the get pointer, implying full pool.
                // note that (p >= g + m_capacity) is a bug.
                return false;
            }

            // 2. conquer this cell by incrementing the put index
            if (!m_put.compareAndSet(p, p + 1)) {
                // some other thread got here first. try again.
                continue;
            }

            // 3. put the object in the cell
            int index = p % m_arraySize;
            AtomicReference<T> reference = m_array[index];
            if (reference.compareAndSet(null, object)) {
                return true;
            }

            // getting here is rare. the object that was supposedly conquered
            // locally was replaced with a different object in the same cell.
        }
    }