当前位置: 首页>>代码示例>>Java>>正文


Java GenericObjectPool.setMaxTotal方法代码示例

本文整理汇总了Java中org.apache.commons.pool2.impl.GenericObjectPool.setMaxTotal方法的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPool.setMaxTotal方法的具体用法?Java GenericObjectPool.setMaxTotal怎么用?Java GenericObjectPool.setMaxTotal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.pool2.impl.GenericObjectPool的用法示例。


在下文中一共展示了GenericObjectPool.setMaxTotal方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
private ObjectPool<PoolableConnection> createPool(String connectionString) {
    // A ConnectionFactory that the pool will use to create Connections.
    ConnectionFactory connectionFactory =
            new DriverManagerConnectionFactory(connectionString, null);
    // PoolableConnectionFactory wraps the real Connections with the
    // classes that implement the pooling functionality.
    PoolableConnectionFactory poolableConnectionFactory =
            new PoolableConnectionFactory(connectionFactory, null);
    poolableConnectionFactory.setValidationQuery("SELECT 1");

    // Actual pool of connections.
    GenericObjectPool<PoolableConnection> connectionPool =
            new GenericObjectPool<>(poolableConnectionFactory);
    int connMax = getConfig()
            .getInt(OctopusConfiguration.MASTER_CONNECTION_POOL_MAX, 8);
    connectionPool.setMaxTotal(connMax);
    connectionPool.setTestOnBorrow(true);
    // Set the factory's pool property to the owning pool.
    poolableConnectionFactory.setPool(connectionPool);

    return connectionPool;
}
 
开发者ID:bitnine-oss,项目名称:octopus,代码行数:23,代码来源:ConnectionManager.java

示例2: initializeThriftConnectionPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
 * Initialize a new thrift client connection pool.
 */
private void initializeThriftConnectionPool() {

    int thriftClientPoolSize = AndesConfigurationManager
            .readValue(AndesConfiguration.PERFORMANCE_TUNING_THRIFT_CLIENT_POOL_SIZE);

    GenericObjectPool<SlotManagementService.Client> thriftConnectionPool = new GenericObjectPool<>(
            thriftClientFactory);
    thriftConnectionPool.setMaxTotal(thriftClientPoolSize);
    thriftConnectionPool.setTestOnBorrow(true);
    if (socketTimeout > 0) {
        thriftConnectionPool.setTimeBetweenEvictionRunsMillis(socketTimeout / 2);
        thriftConnectionPool.setMinEvictableIdleTimeMillis(socketTimeout);
    }
    thriftClientPool = thriftConnectionPool;
}
 
开发者ID:wso2,项目名称:andes,代码行数:19,代码来源:MBThriftClient.java

示例3: createConnectionPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
 * Creates a connection pool for this datasource.  This method only exists
 * so subclasses can replace the implementation class.
 *
 * This implementation configures all pool properties other than
 * timeBetweenEvictionRunsMillis.  Setting that property is deferred to
 * {@link #startPoolMaintenance()}, since setting timeBetweenEvictionRunsMillis
 * to a positive value causes {@link GenericObjectPool}'s eviction timer
 * to be started.
 */
protected void createConnectionPool(final PoolableConnectionFactory factory) {
    // Create an object pool to contain our active connections
    final GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    updateJmxName(config);
    config.setJmxEnabled(registeredJmxObjectName != null);  // Disable JMX on the underlying pool if the DS is not registered.
    final GenericObjectPool<PoolableConnection> gop = createObjectPool(factory, config, abandonedConfig);
    gop.setMaxTotal(maxTotal);
    gop.setMaxIdle(maxIdle);
    gop.setMinIdle(minIdle);
    gop.setMaxWaitMillis(maxWaitMillis);
    gop.setTestOnCreate(testOnCreate);
    gop.setTestOnBorrow(testOnBorrow);
    gop.setTestOnReturn(testOnReturn);
    gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    gop.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
    gop.setTestWhileIdle(testWhileIdle);
    gop.setLifo(lifo);
    gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log, logExpiredConnections));
    gop.setEvictionPolicyClassName(evictionPolicyClassName);
    factory.setPool(gop);
    connectionPool = gop;
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:34,代码来源:BasicDataSource.java

示例4: testFixFactoryConfig

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
 * DBCP-412
 * Verify that omitting factory.setPool(pool) when setting up PDS does not
 * result in NPE.
 */
@Test
public void testFixFactoryConfig() throws Exception {
    final Properties props = new Properties();
    props.setProperty("user", "username");
    props.setProperty("password", "password");
    final PoolableConnectionFactory f =
        new PoolableConnectionFactory(
                new DriverConnectionFactory(new TesterDriver(),
                        "jdbc:apache:commons:testdriver", props),
                null);
    f.setValidationQuery("SELECT DUMMY FROM DUAL");
    f.setDefaultReadOnly(Boolean.TRUE);
    f.setDefaultAutoCommit(Boolean.TRUE);
    final GenericObjectPool<PoolableConnection> p = new GenericObjectPool<>(f);
    p.setMaxTotal(getMaxTotal());
    p.setMaxWaitMillis(getMaxWaitMillis());
    ds = new PoolingDataSource<>(p);
    assertTrue(f.getPool().equals(p));
    ds.getConnection();
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:26,代码来源:TestPoolingDataSource.java

示例5: createProcessPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
private GenericObjectPool<PhantomJSProcess> createProcessPool(JRPropertiesUtil properties)
{
	ProcessFactory processFactory = new ProcessFactory(this, properties);
	GenericObjectPool<PhantomJSProcess> pool = new GenericObjectPool<>(processFactory);
	pool.setLifo(true);
	
	int maxProcessCount = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_MAX_PROCESS_COUNT, 
			PhantomJS.DEFAULT_PHANTOMJS_MAX_PROCESS_COUNT);
	pool.setMaxTotal(maxProcessCount);
	pool.setMaxIdle(maxProcessCount);
	
	int borrowTimeout = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_POOL_BORROW_TIMEOUT, 
			PhantomJS.DEFAULT_PHANTOMJS_POOL_BORROW_TIMEOUT);
	pool.setMaxWaitMillis(borrowTimeout);
	
	int idleTimeout = properties.getIntegerProperty(PhantomJS.PROPERTY_PHANTOMJS_IDLE_TIMEOUT, 
			PhantomJS.DEFAULT_PHANTOMJS_IDLE_TIMEOUT);
	pool.setMinEvictableIdleTimeMillis(idleTimeout);
	
	pool.setTimeBetweenEvictionRunsMillis(idlePingInterval);
	
	pool.setTestWhileIdle(true);
	pool.setNumTestsPerEvictionRun(Integer.MAX_VALUE);
	
	pool.setSwallowedExceptionListener(new SwallowedExceptionListener()
	{
		@Override
		public void onSwallowException(Exception e)
		{
			if (log.isDebugEnabled())
			{
				log.debug("Pool exception", e);
			}
		}
	});
	
	return pool;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:39,代码来源:ProcessDirector.java

示例6: createDataSource

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
/**
 * Create an automatically managed pool of database connections to the supplied JDBC database URL.
 *
 * Creating new database connections is usually an expensive operation,
 * taking up to seconds to prepare for a transaction that only lasts milliseconds.
 * The JDBC in Java 7 and 8 support connection pooling, which is critical for performance.
 * We are using the standard JDBC DataSource interface, with the Apache commons-dbcp implementation.
 * This should be roughly the same connection pooling used in the Tomcat application server.
 *
 * Here are some sample database URLs to serve as patterns:
 * H2_FILE_URL = "jdbc:h2:file:~/test-db"; // H2 memory does not seem faster than H2 file
 * SQLITE_FILE_URL = "jdbc:sqlite:/Users/abyrd/test-db";
 * POSTGRES_LOCAL_URL = "jdbc:postgresql://localhost/catalogue";
 *
 * For local Postgres connections, you can supply a null username and password to use host-based authentication.
 */
public static DataSource createDataSource (String url, String username, String password) {
    String characterEncoding = Charset.defaultCharset().toString();
    LOG.debug("Default character encoding: {}", characterEncoding);
    if (!Charset.defaultCharset().equals(StandardCharsets.UTF_8)) {
        // Character encoding must be set to UTF-8 in order for the database connection to work without error.
        // To override default encoding at runtime, run application jar with encoding environment variable set to
        // UTF-8 (or update IDE settings). TODO we should also check that JDBC and the database know to use UTF-8.
        throw new RuntimeException("Your system's default encoding (" + characterEncoding + ") is not supported. Please set it to UTF-8. Example: java -Dfile.encoding=UTF-8 application.jar");
    }
    // ConnectionFactory can handle null username and password (for local host-based authentication)
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, username, password);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
    // TODO: set other options on connectionPool?
    connectionPool.setMaxTotal(300);
    connectionPool.setMaxIdle(4);
    connectionPool.setMinIdle(2);
    poolableConnectionFactory.setPool(connectionPool);
    // We also want auto-commit switched off for bulk inserts, and also because fetches are super-slow with
    // auto-commit turned on. Apparently it interferes with result cursors.
    poolableConnectionFactory.setDefaultAutoCommit(false);
    return new PoolingDataSource(connectionPool);
    // We might want already-loaded feeds to be treated as read-only.
    // But we need to call this on the connection, not the connectionSource.
    // connection.setReadOnly();
    // Not sure we need to close cursors - closing the pool-wrapped connection when we're done with it should also close cursors.
    // will this help? https://stackoverflow.com/a/18300252
    // connection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
}
 
开发者ID:conveyal,项目名称:gtfs-lib,代码行数:46,代码来源:GTFS.java

示例7: init

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
synchronized public ThriftClientPool<T, I> init() {
    if (thriftClientPool == null) {
        if (tprotocolFactory == null) {
            throw new IllegalStateException("No ITProtocolFactory instance found!");
        }
        if (retryPolicy == null) {
            retryPolicy = RetryPolicy.DEFAULT;
        }

        ThriftClientFactory factory = new ThriftClientFactory();
        GenericObjectPool<I> pool = new GenericObjectPool<I>(factory);
        pool.setBlockWhenExhausted(true);
        pool.setTestOnReturn(false);
        int maxActive = poolConfig != null ? poolConfig.getMaxActive()
                : PoolConfig.DEFAULT_MAX_ACTIVE;
        long maxWaitTime = poolConfig != null ? poolConfig.getMaxWaitTime()
                : PoolConfig.DEFAULT_MAX_WAIT_TIME;
        int maxIdle = poolConfig != null ? poolConfig.getMaxIdle()
                : PoolConfig.DEFAULT_MAX_IDLE;
        int minIdle = poolConfig != null ? poolConfig.getMinIdle()
                : PoolConfig.DEFAULT_MIN_IDLE;
        pool.setMaxTotal(maxActive);
        pool.setMaxIdle(maxIdle);
        pool.setMinIdle(minIdle);
        pool.setMaxWaitMillis(maxWaitTime);
        pool.setTestOnBorrow(poolConfig != null ? poolConfig.isTestOnBorrow() : false);
        pool.setTestOnCreate(poolConfig != null ? poolConfig.isTestOnCreate() : false);
        pool.setTestWhileIdle(poolConfig != null ? poolConfig.isTestWhileIdle() : false);
        pool.setTimeBetweenEvictionRunsMillis(10000);
        this.thriftClientPool = pool;
    }
    return this;
}
 
开发者ID:DDTH,项目名称:ddth-thriftpool,代码行数:34,代码来源:ThriftClientPool.java

示例8: testClose

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
@Test
public void testClose() throws Exception {

    final Properties props = new Properties();
    props.setProperty("user", "username");
    props.setProperty("password", "password");
    final PoolableConnectionFactory f =
        new PoolableConnectionFactory(
                new DriverConnectionFactory(new TesterDriver(),
                        "jdbc:apache:commons:testdriver", props),
                null);
    f.setValidationQuery("SELECT DUMMY FROM DUAL");
    f.setDefaultReadOnly(Boolean.TRUE);
    f.setDefaultAutoCommit(Boolean.TRUE);
    final GenericObjectPool<PoolableConnection> p = new GenericObjectPool<>(f);
    p.setMaxTotal(getMaxTotal());
    p.setMaxWaitMillis(getMaxWaitMillis());

    try ( PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(p) ) {
        final Connection connection = dataSource.getConnection();
        assertNotNull(connection);
        connection.close();
    }

    assertTrue(p.isClosed());
    assertEquals(0, p.getNumIdle());
    assertEquals(0, p.getNumActive());
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:29,代码来源:TestPoolingDataSource.java

示例9: createDbcp

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
private void createDbcp(DbcpConfig conf)
{
	if (!dataSources.containsKey(conf.name))
	{
		try
	    {
			
			Class.forName(conf.driverClassName);
		    
		    DriverManagerConnectionFactory cf =  new DriverManagerConnectionFactory(conf.jdbc,conf.user,conf.password);
		    
		    PoolableConnectionFactory pcf  =  new PoolableConnectionFactory(cf,null);
		    pcf.setValidationQuery(conf.validationQuery);
		    //, pool, null, conf.validationQuery, false, true,abandondedConfig);
			
		    logger.info("Creating pool "+conf.toString());
		    // create a generic pool
		    GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(pcf);
		    pool.setMaxTotal(conf.maxTotal);
		    pool.setMaxIdle(conf.maxIdle);
		    pool.setMinIdle(conf.minIdle);
		    pool.setMaxWaitMillis(conf.maxWait);
		    pool.setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis);
		    pool.setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis);
		    pool.setTestWhileIdle(conf.testWhileIdle);
		    pool.setTestOnBorrow(conf.testOnBorrow);
	    
		    AbandonedConfig abandonedConfig = new AbandonedConfig();
		    abandonedConfig.setRemoveAbandonedOnMaintenance(conf.removeAbanadoned);
		    abandonedConfig.setRemoveAbandonedTimeout(conf.removeAbandonedTimeout);
		    abandonedConfig.setLogAbandoned(conf.logAbandonded);
	    
		    pool.setAbandonedConfig(abandonedConfig);
	    
		    pcf.setPool(pool);
		    DataSource ds = new PoolingDataSource(pool);
		    dataSources.put(conf.name, ds);

	    } catch (ClassNotFoundException e) {
			logger.error("Failed to create datasource for "+conf.name+ " with class "+conf.driverClassName);
		}
	   
	}
	else
	{
		logger.error("Pool "+conf.name+" already exists. Can't change existing datasource at present.");
	}
}
 
开发者ID:SeldonIO,项目名称:seldon-server,代码行数:49,代码来源:DbcpFactory.java

示例10: registerPool

import org.apache.commons.pool2.impl.GenericObjectPool; //导入方法依赖的package包/类
private synchronized void registerPool(final String username, final String password)
        throws NamingException, SQLException {

    final ConnectionPoolDataSource cpds = testCPDS(username, password);

    // Set up the factory we will use (passing the pool associates
    // the factory with the pool, so we do not have to do so
    // explicitly)
    final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds,
            getValidationQuery(), getValidationQueryTimeout(),
            isRollbackAfterValidation(), username, password);
    factory.setMaxConnLifetimeMillis(getMaxConnLifetimeMillis());

    // Create an object pool to contain our PooledConnections
    final GenericObjectPool<PooledConnectionAndInfo> pool =
            new GenericObjectPool<>(factory);
    factory.setPool(pool);
    pool.setBlockWhenExhausted(getPerUserBlockWhenExhausted(username));
    pool.setEvictionPolicyClassName(
            getPerUserEvictionPolicyClassName(username));
    pool.setLifo(getPerUserLifo(username));
    pool.setMaxIdle(getPerUserMaxIdle(username));
    pool.setMaxTotal(getPerUserMaxTotal(username));
    pool.setMaxWaitMillis(getPerUserMaxWaitMillis(username));
    pool.setMinEvictableIdleTimeMillis(
            getPerUserMinEvictableIdleTimeMillis(username));
    pool.setMinIdle(getPerUserMinIdle(username));
    pool.setNumTestsPerEvictionRun(
            getPerUserNumTestsPerEvictionRun(username));
    pool.setSoftMinEvictableIdleTimeMillis(
            getPerUserSoftMinEvictableIdleTimeMillis(username));
    pool.setTestOnCreate(getPerUserTestOnCreate(username));
    pool.setTestOnBorrow(getPerUserTestOnBorrow(username));
    pool.setTestOnReturn(getPerUserTestOnReturn(username));
    pool.setTestWhileIdle(getPerUserTestWhileIdle(username));
    pool.setTimeBetweenEvictionRunsMillis(
            getPerUserTimeBetweenEvictionRunsMillis(username));

    pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));

    final Object old = managers.put(getPoolKey(username), factory);
    if (old != null) {
        throw new IllegalStateException("Pool already contains an entry for this user/password: " + username);
    }
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:46,代码来源:PerUserPoolDataSource.java


注:本文中的org.apache.commons.pool2.impl.GenericObjectPool.setMaxTotal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。