Codota Logo
GenericObjectPool
Code IndexAdd Codota to your IDE (free)

How to use
GenericObjectPool
in
org.apache.commons.pool.impl

Best Java code snippets using org.apache.commons.pool.impl.GenericObjectPool (Showing top 20 results out of 909)

  • Common ways to obtain GenericObjectPool
private void myMethod () {
GenericObjectPool g =
  • Codota Iconnew GenericObjectPool()
  • Codota Iconnew GenericObjectPool(null)
  • Codota IconPoolableObjectFactory factory;new GenericObjectPool(factory)
  • Smart code suggestions by Codota
}
origin: apache/hive

boolean lifo = hdpConfig.getBoolean(CONNECTION_LIFO, GenericObjectPool.DEFAULT_LIFO);
GenericObjectPool objectPool = new GenericObjectPool();
objectPool.setMaxActive(maxPoolSize);
objectPool.setMaxWait(connectionTimeout);
objectPool.setMaxIdle(connectionMaxIlde);
objectPool.setMinIdle(connectionMinIlde);
objectPool.setTestOnBorrow(testOnBorrow);
objectPool.setTestWhileIdle(testWhileIdle);
objectPool.setMinEvictableIdleTimeMillis(evictionTimeMillis);
objectPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns);
objectPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
objectPool.setTestOnReturn(testOnReturn);
objectPool.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
objectPool.setLifo(lifo);
origin: BroadleafCommerce/BroadleafCommerce

@Override
public void close() throws SQLException {
  try {
    connectionPool.returnObject(this);
  } catch (Exception e) {
    throw new SQLException(e);
  }
}
origin: weibocom/motan

protected Channel borrowObject() throws Exception {
  Channel nettyChannel = (Channel) pool.borrowObject();
  if (nettyChannel != null && nettyChannel.isAvailable()) {
    return nettyChannel;
  }
  invalidateObject(nettyChannel);
  String errorMsg = this.getClass().getSimpleName() + " borrowObject Error: url=" + url.getUri();
  LoggerUtil.error(errorMsg);
  throw new MotanServiceException(errorMsg);
}
origin: commons-pool/commons-pool

/**
 * Sets my configuration.
 *
 * @param conf configuration to use.
 * @see GenericObjectPool.Config
 */
public void setConfig(GenericObjectPool.Config conf) {
  synchronized (this) {
    setMaxIdle(conf.maxIdle);
    setMinIdle(conf.minIdle);
    setMaxActive(conf.maxActive);
    setMaxWait(conf.maxWait);
    setWhenExhaustedAction(conf.whenExhaustedAction);
    setTestOnBorrow(conf.testOnBorrow);
    setTestOnReturn(conf.testOnReturn);
    setTestWhileIdle(conf.testWhileIdle);
    setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun);
    setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis);
    setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis);
    setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis);
    setLifo(conf.lifo);
  }
  allocate();
}
origin: commons-pool/commons-pool

allocate();
    assertOpen();
            if(isClosed() == true) {
              throw new IllegalStateException("Pool closed");
                returnObject(latch.getPair().getValue());
              allocate();
        allocate();
    allocate();
    if(newlyCreated) {
      throw new NoSuchElementException("Could not create a validated object, cause: " + e.getMessage());
origin: apache/flume

  new DriverManagerConnectionFactory(connectUrl, jdbcProps);
connectionPool = new GenericObjectPool();
connectionPool.setMaxActive(maxActive);
origin: springframework/spring-aop

/**
 * Subclasses can override this if they want to return a specific Commons pool.
 * They should apply any configuration properties to the pool here.
 * <p>Default is a GenericObjectPool instance with the given pool size.
 * @return an empty Commons <code>ObjectPool</code>.
 * @see org.apache.commons.pool.impl.GenericObjectPool
 * @see #setMaxSize
 */
protected ObjectPool createObjectPool() {
  GenericObjectPool gop = new GenericObjectPool(this);
  gop.setMaxActive(getMaxSize());
  gop.setMaxIdle(getMaxIdle());
  gop.setMinIdle(getMinIdle());
  gop.setMaxWait(getMaxWait());
  gop.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
  gop.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
  gop.setWhenExhaustedAction(getWhenExhaustedAction());
  return gop;
}
origin: org.mule.modules/mule-module-xml

private GenericObjectPool<XPathExpression> getXPathExpressionPool(String expression)
{
  GenericObjectPool genericPool = new GenericObjectPool(new XPathExpressionFactory(xpathFactory, expression, namespaceContext, this));
  genericPool.setMaxActive(MAX_ACTIVE_XPATH_EXPRESSIONS);
  genericPool.setMaxIdle(MAX_IDLE_XPATH_EXPRESSIONS);
  genericPool.setMinIdle(MIN_IDLE_XPATH_EXPRESSIONS);
  return genericPool;
}
origin: shunyang/thrift-all

@Override
public void afterPropertiesSet() throws Exception {
  // 对象池
  objectPool = new GenericObjectPool<TTransport>();
  //
  ((GenericObjectPool<TTransport>) objectPool).setMaxActive(maxActive);
  ((GenericObjectPool<TTransport>) objectPool).setMaxIdle(maxIdle);
  ((GenericObjectPool<TTransport>) objectPool).setMinIdle(minIdle);
  ((GenericObjectPool<TTransport>) objectPool).setMaxWait(maxWait);
  ((GenericObjectPool<TTransport>) objectPool).setTestOnBorrow(testOnBorrow);
  ((GenericObjectPool<TTransport>) objectPool).setTestOnReturn(testOnReturn);
  ((GenericObjectPool<TTransport>) objectPool).setTestWhileIdle(testWhileIdle);
  ((GenericObjectPool<TTransport>) objectPool).setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
  // 设置factory
  ThriftPoolableObjectFactory thriftPoolableObjectFactory = new ThriftPoolableObjectFactory(serviceIP, servicePort, conTimeOut);
  ((GenericObjectPool<TTransport>) objectPool).setFactory(thriftPoolableObjectFactory);
}
origin: commons-pool/commons-pool

/**
 * {@inheritDoc}
 */
public ObjectPool<T> createPool() {
  return new GenericObjectPool<T>(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_softMinEvictableIdleTimeMillis,_lifo);
}
origin: org.hobsoft.symmetry/symmetry-core

public DefaultComponentPool(PoolableObjectFactory objectFactory)
{
  pool = new GenericObjectPool(objectFactory);
  
  pool.setMinIdle(POOL_SIZE);
  pool.setMaxActive(POOL_SIZE);
  pool.setNumTestsPerEvictionRun(0);
  pool.setMinEvictableIdleTimeMillis(0);
  pool.setTimeBetweenEvictionRunsMillis(POOL_SPAWN_DELAY);
}
 
origin: stackoverflow.com

GenericObjectPool connectionPool = new GenericObjectPool(null);
 connectionPool.setMinEvictableIdleTimeMillis(1000 * 60 * 30);
 connectionPool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 30);
 connectionPool.setNumTestsPerEvictionRun(3);
 connectionPool.setTestOnBorrow(true);
 connectionPool.setTestWhileIdle(false);
 connectionPool.setTestOnReturn(false);
 props = new Properties();
 props.put("user", username);
 props.put("password", password);
 ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, props);
 PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, "SELECT 1", false, true);
 PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
origin: org.eobjects.analyzerbeans/AnalyzerBeans-core

/**
 * Creates a connection pool that can be used for one or more
 * {@link PooledServiceSession} objects.
 * 
 * @param maxConnections
 * @return
 */
public static GenericObjectPool<Integer> createConnectionPool(int maxConnections) {
  GenericObjectPool<Integer> connectionPool = new GenericObjectPool<Integer>(new ConnectionPoolObjectFactory());
  connectionPool.setMaxActive(maxConnections);
  connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
  return connectionPool;
}
origin: org.wso2.carbon.identity.agent.entitlement.mediator/org.wso2.carbon.identity.entitlement.proxy

private EntitlementServiceStub getEntitlementStub(String serverUrl) throws Exception {
  if (configurationContext == null) {
    throw new EntitlementProxyException("Cannot initialize EntitlementServiceStub with null Axis2 " +
                      "configuration context.");
  }
  if (serviceStubPool == null) {
    serviceStubPool = new GenericObjectPool(new EntitlementServiceStubFactory(
            configurationContext, serverUrl + ENTITLEMENT_SERVICE_NAME, authenticator));
  }
  return (EntitlementServiceStub) serviceStubPool.borrowObject();
}
origin: geotools/geotools

pool = new GenericObjectPool(seConnectionFactory, poolCfg);
  preload[i] = (ISession) pool.borrowObject();
  if (i == 0) {
    SeRelease seRelease = preload[i].getRelease();
  pool.returnObject(preload[i]);
origin: org.gosu-lang.tosa/tosa-runtime

 private DataSource setupDataSource(String connectURI, IModule module) {
  // Ensure the JDBC driver class is loaded
   // TODO - AHK
  final List<? extends ITypeLoader> typeLoaders = module.getTypeLoaders(IDefaultTypeLoader.class);
  ((IDefaultTypeLoader)typeLoaders.get(0)).loadClass(getDriverName(connectURI));

  // TODO - AHK - Figure out the implications of the connection pooling when the jdbc url changes

  GenericObjectPool connectionPool = new GenericObjectPool(null);
  connectionPool.setMinIdle( 1 );
  connectionPool.setMaxActive( 10 );

  ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);
  PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);

  return new PoolingDataSource(connectionPool);
 }
}
origin: uk.org.mygrid.resources/boca-model

private void setupPool(GenericObjectPool pool, RepositoryConnectionFactory factory, int maxActive, int maxIdle, long blockWait) {
  pool.setFactory(factory);
  pool.setMaxActive(maxActive);
  pool.setMaxIdle(maxIdle);
  pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
  pool.setMaxWait(blockWait);
}
origin: apache/flume

@Override
public void close() {
 try {
  connectionPool.close();
 } catch (Exception ex) {
  throw new JdbcChannelException("Unable to close connection pool", ex);
origin: banq/jdonframework

public void setMaxPoolSize(int maxPoolSize) {
  pool.setMaxActive(maxPoolSize);
}
origin: org.mule.modules/mule-module-xml

/**
 * Sets the the current maximum number of idle transformer objects allowed in the pool
 *
 * @param maxIdleTransformers New maximum size to set
 */
public void setMaxIdleTransformers(int maxIdleTransformers)
{
  transformerPool.setMaxIdle(maxIdleTransformers);
}
org.apache.commons.pool.implGenericObjectPool

Javadoc

A configurable ObjectPool implementation.

When coupled with the appropriate PoolableObjectFactory, GenericObjectPool provides robust pooling functionality for arbitrary objects.

A GenericObjectPool provides a number of configurable parameters:

  • #setMaxActive controls the maximum number of objects that can be allocated by the pool (checked out to clients, or idle awaiting checkout) at a given time. When non-positive, there is no limit to the number of objects that can be managed by the pool at one time. When #setMaxActive is reached, the pool is said to be exhausted. The default setting for this parameter is 8.
  • #setMaxIdle controls the maximum number of objects that can sit idle in the pool at any time. When negative, there is no limit to the number of objects that may be idle at one time. The default setting for this parameter is 8.
  • #setWhenExhaustedAction specifies the behavior of the #borrowObject method when the pool is exhausted:
    • When #setWhenExhaustedAction is #WHEN_EXHAUSTED_FAIL, #borrowObject will throw a NoSuchElementException
    • When #setWhenExhaustedAction is #WHEN_EXHAUSTED_GROW, #borrowObject will create a new object and return it (essentially making #setMaxActivemeaningless.)
    • When #setWhenExhaustedActionis #WHEN_EXHAUSTED_BLOCK, #borrowObject will block (invoke Object#wait()) until a new or idle object is available. If a positive #setMaxWaitvalue is supplied, then #borrowObject will block for at most that many milliseconds, after which a NoSuchElementExceptionwill be thrown. If #setMaxWait is non-positive, the #borrowObject method will block indefinitely.
    The default whenExhaustedAction setting is #WHEN_EXHAUSTED_BLOCK and the default maxWait setting is -1. By default, therefore, borrowObject will block indefinitely until an idle instance becomes available.
  • When #setTestOnBorrow is set, the pool will attempt to validate each object before it is returned from the #borrowObject method. (Using the provided factory's PoolableObjectFactory#validateObject method.) Objects that fail to validate will be dropped from the pool, and a different object will be borrowed. The default setting for this parameter is false.
  • When #setTestOnReturn is set, the pool will attempt to validate each object before it is returned to the pool in the #returnObject method. (Using the provided factory's PoolableObjectFactory#validateObjectmethod.) Objects that fail to validate will be dropped from the pool. The default setting for this parameter is false.

Optionally, one may configure the pool to examine and possibly evict objects as they sit idle in the pool and to ensure that a minimum number of idle objects are available. This is performed by an "idle object eviction" thread, which runs asynchronously. Caution should be used when configuring this optional feature. Eviction runs require an exclusive synchronization lock on the pool, so if they run too frequently and / or incur excessive latency when creating, destroying or validating object instances, performance issues may result. The idle object eviction thread may be configured using the following attributes:

  • #setTimeBetweenEvictionRunsMillisindicates how long the eviction thread should sleep before "runs" of examining idle objects. When non-positive, no eviction thread will be launched. The default setting for this parameter is -1 (i.e., idle object eviction is disabled by default).
  • #setMinEvictableIdleTimeMillisspecifies the minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due to idle time. When non-positive, no object will be dropped from the pool due to idle time alone. This setting has no effect unless timeBetweenEvictionRunsMillis > 0. The default setting for this parameter is 30 minutes.
  • #setTestWhileIdle indicates whether or not idle objects should be validated using the factory's PoolableObjectFactory#validateObject method. Objects that fail to validate will be dropped from the pool. This setting has no effect unless timeBetweenEvictionRunsMillis > 0. The default setting for this parameter is false.
  • #setSoftMinEvictableIdleTimeMillisspecifies the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any), with the extra condition that at least "minIdle" object instances remain in the pool. When non-positive, no objects will be evicted from the pool due to idle time alone. This setting has no effect unless timeBetweenEvictionRunsMillis > 0. and it is superceded by #setMinEvictableIdleTimeMillis(that is, if minEvictableIdleTimeMillis is positive, then softMinEvictableIdleTimeMillis is ignored). The default setting for this parameter is -1 (disabled).
  • #setNumTestsPerEvictionRundetermines the number of objects examined in each run of the idle object evictor. This setting has no effect unless timeBetweenEvictionRunsMillis > 0. The default setting for this parameter is 3.

The pool can be configured to behave as a LIFO queue with respect to idle objects - always returning the most recently used object from the pool, or as a FIFO queue, where borrowObject always returns the oldest object in the idle object pool.

  • #setLifodetermines whether or not the pool returns idle objects in last-in-first-out order. The default setting for this parameter is true.

GenericObjectPool is not usable without a PoolableObjectFactory. A non-null factory must be provided either as a constructor argument or via a call to #setFactory before the pool is used.

Implementation note: To prevent possible deadlocks, care has been taken to ensure that no call to a factory method will occur within a synchronization block. See POOL-125 and DBCP-44 for more information.

Most used methods

  • <init>
    Create a new GenericObjectPool using the specified values.
  • returnObject
    Returns an object instance to the pool. If #getMaxIdle() is set to a positive value and the number
  • borrowObject
    Borrows an object from the pool. If there is an idle instance available in the pool, then either th
  • setMaxActive
    Sets the cap on the number of objects that can be allocated by the pool (checked out to clients, or
  • close
    Closes the pool. Once the pool is closed, #borrowObject()will fail with IllegalStateException, but #
  • setMaxIdle
    Sets the cap on the number of "idle" instances in the pool. If maxIdle is set too low on heavily loa
  • setMinIdle
    Sets the minimum number of objects allowed in the pool before the evictor thread (if active) spawns
  • setTimeBetweenEvictionRunsMillis
    Sets the number of milliseconds to sleep between runs of the idle object evictor thread. When non-po
  • setMinEvictableIdleTimeMillis
    Sets the minimum amount of time an object may sit idle in the pool before it is eligible for evictio
  • setMaxWait
    Sets the maximum amount of time (in milliseconds) the #borrowObject method should block before throw
  • setTestOnBorrow
    When true, objects will be PoolableObjectFactory#validateObjectbefore being returned by the #borrowO
  • setWhenExhaustedAction
    Sets the action to take when the #borrowObject method is invoked when the pool is exhausted (the max
  • setTestOnBorrow,
  • setWhenExhaustedAction,
  • getNumActive,
  • getNumIdle,
  • setTestWhileIdle,
  • setNumTestsPerEvictionRun,
  • setTestOnReturn,
  • invalidateObject,
  • clear,
  • addObject

Popular in Java

  • Start an intent from android
  • notifyDataSetChanged (ArrayAdapter)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • onCreateOptionsMenu (Activity)
  • MalformedURLException (java.net)
    Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a s
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JFileChooser (javax.swing)
  • JLabel (javax.swing)
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now