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


Java GenericObjectPool类代码示例

本文整理汇总了Java中org.apache.commons.pool.impl.GenericObjectPool的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPool类的具体用法?Java GenericObjectPool怎么用?Java GenericObjectPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: DBManager

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
public DBManager() {
 ResourceBundle rb = PropertyResourceBundle.getBundle(
    "com.gint.app.bisisadmin.Config");
 String driver     = rb.getString("driver");
 String URL        = rb.getString("url");
 String username   = rb.getString("username");
 String password   = rb.getString("password");
	
 try {
   Class.forName(driver);
   GenericObjectPool connectionPool = new GenericObjectPool(null);
   DriverManagerConnectionFactory connectionFactory = 
     new DriverManagerConnectionFactory(URL, username, password);
   PoolableConnectionFactory poolableConnectionFactory =
     new PoolableConnectionFactory(connectionFactory, connectionPool, null, 
         null, false, false);
   poolingDataSource = new PoolingDataSource(connectionPool);
 } catch (Exception ex) {
   ex.printStackTrace();
 }  
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:22,代码来源:DBManager.java

示例2: main

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  Class.forName("com.mysql.jdbc.Driver");
  GenericObjectPool connectionPool = new GenericObjectPool(null);
  DriverManagerConnectionFactory connectionFactory = 
    new DriverManagerConnectionFactory("jdbc:mysql://localhost/bisis35?characterEncoding=UTF-8", 
        "bisis35", "bisis35");
  PoolableConnectionFactory poolableConnectionFactory =
    new PoolableConnectionFactory(connectionFactory, connectionPool, null, 
        null, false, true);
  PoolingDataSource poolingDataSource = new PoolingDataSource(connectionPool);
  
  RecordManagerImpl recMgr = new RecordManagerImpl();
  recMgr.setDataSource(poolingDataSource);
  
  Record rec1 = recMgr.getRecord(1);
  
  System.out.println(rec1);
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:19,代码来源:RetrieverTest.java

示例3: ConnectionPooling

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
/**
 * Constructor 
 *
 * Params:
 *
 *
 */
public ConnectionPooling(String connectionURL, String userName, String password, String driverName) throws ClassNotFoundException, SQLException{
	Class.forName(driverName);
	
	Properties props = new Properties();
	props.setProperty("user", userName);
	props.setProperty("password", password);
	
	ObjectPool connectionPool = new GenericObjectPool(null);
	
	ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectionURL, props);
	
	PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, 
			connectionPool, null, null, false, true);
	
	
	Class.forName("org.apache.commons.dbcp.PoolingDriver");
       PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(myPoolingDriverName);
       driver.registerPool(myPoolName,connectionPool);
}
 
开发者ID:claresco,项目名称:Tinman,代码行数:27,代码来源:ConnectionPooling.java

示例4: refreshChannelPool

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
/**
 * Refresh the channel pool for the server.
 *
 * @param loc server address
 */
public void refreshChannelPool(Location loc) {
  try {
    lock.lock();
    GenericObjectPool<Channel> pool = locToChannelPoolMap.get(loc);
    if(pool == null) {
      return;
    } else {
      try {
        pool.close();
      } catch (Exception e) {
        LOG.error("Close channel for location " + loc +" error ", e);
      }
    }

    locToChannelPoolMap.put(loc, createPool(loc, pool.getNumActive() / 5));
  } finally {
    lock.unlock();
  }
}
 
开发者ID:Tencent,项目名称:angel,代码行数:25,代码来源:ChannelManager.java

示例5: removeChannelPool

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
/**
 * Remove the channel pool for the server.
 *
 * @param loc server address
 */
public void removeChannelPool(Location loc) {
  try {
    lock.lock();
    GenericObjectPool<Channel> pool = locToChannelPoolMap.remove(loc);
    if (pool != null) {
      try {
        pool.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  } finally {
    lock.unlock();
  }
}
 
开发者ID:Tencent,项目名称:angel,代码行数:21,代码来源:ChannelManager.java

示例6: clear

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
/**
 * Clear and close all channels.
 */
public void clear() {
  try {
    lock.lock();
    for (Entry<Location, GenericObjectPool<Channel>> entry : locToChannelPoolMap.entrySet()) {
      try {
        entry.getValue().close();
      } catch (Exception e) {
        LOG.error("close channel pool failed, ", e);
      }
    }
    locToChannelPoolMap.clear();
  } finally {
    lock.unlock();
  }
}
 
开发者ID:Tencent,项目名称:angel,代码行数:19,代码来源:ChannelManager.java

示例7: createManagedDataSource

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
private DataSource createManagedDataSource(DataSource ds) {

        // wrap it with a LocalXAConnectionFactory
        XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(
                transactionManager, new DataSourceConnectionFactory(ds));

        GenericObjectPool pool = new GenericObjectPool();

        // create the pool object factory
        PoolableConnectionFactory factory = new PoolableConnectionFactory(
                xaConnectionFactory, pool, null, "SELECT DUMMY FROM DUAL",
                false, false);
        pool.setFactory(factory);

        ManagedDataSource managedDs = new ManagedDataSource(pool,
                xaConnectionFactory.getTransactionRegistry());
        managedDs.setAccessToUnderlyingConnectionAllowed(true);
        return managedDs;
    }
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:TestPersistence.java

示例8: afterPropertiesSet

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
@Override
    public void afterPropertiesSet() throws Exception {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        // 加载Iface接口
        objectClass = classLoader.loadClass(serverAddressProvider.getService() + "$Iface");
        // 加载Client.Factory类
        Class<TServiceClientFactory<TServiceClient>> fi =
                (Class<TServiceClientFactory<TServiceClient>>) classLoader.
                        loadClass(serverAddressProvider.getService() + "$Client$Factory");
        TServiceClientFactory<TServiceClient> clientFactory = fi.newInstance();

        ThriftClientPoolFactory clientPool = new ThriftClientPoolFactory(serverAddressProvider,
                clientFactory, callback);
        pool = new GenericObjectPool<TServiceClient>(clientPool, makePoolConfig());

//        InvocationHandler handler = makeProxyHandler();//方式1
        InvocationHandler handler = makeProxyHandler2();//方式2
        proxyClient = Proxy.newProxyInstance(classLoader, new Class[] { objectClass }, handler);
    }
 
开发者ID:somewhereMrli,项目名称:albedo-thrift,代码行数:20,代码来源:ThriftServiceClientProxyFactory.java

示例9: getObject

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
@Override
public T getObject() throws Exception {

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    Server server = serverManager.getService(innerClass.getName());

    // 加载Iface接口
    innerClass = classLoader.loadClass(server.getName());
    String temp = server.getName().replace("$Iface", "");
    // 加载Client.Factory类
    Class<TServiceClientFactory<TServiceClient>> fi =
            (Class<TServiceClientFactory<TServiceClient>>) classLoader.
                    loadClass(temp + "$Client$Factory");
    TServiceClientFactory<TServiceClient> clientFactory = fi.newInstance();

    ThriftClientPoolFactory clientPool =
            new ThriftClientPoolFactory(server,
                    clientFactory, callback, proccessName);
    pool = new GenericObjectPool<TServiceClient>(clientPool, makePoolConfig());

    ServiceProxy serviceProxy = new ServiceProxy(pool);

    return (T)Proxy.newProxyInstance(innerClass.getClassLoader(),new Class[]{innerClass}, serviceProxy);

}
 
开发者ID:somewhereMrli,项目名称:albedo-thrift,代码行数:27,代码来源:ProxyFactoryBean.java

示例10: parserServers

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
protected void parserServers(@SuppressWarnings("rawtypes") List nodes)
		throws AlbianRemoteUNIDAttributeException {
	for (Object node : nodes) {
		IAlbianRemoteUNIDAttribute attr = parserServer((Element) node);
		if (null == attr)
			continue;
		_list.add(attr);
		GenericObjectPool.Config config = new GenericObjectPool.Config();
		config.maxActive = attr.getPoolSize();
		config.maxWait = 300;
		GenericObjectPool<Socket> pool = new GenericObjectPool<Socket>(
				new AlbianUNIDSocketConnectPoolFactory(attr),
				config) {
		};
		AlbianUNIDConnectPoolMap.insert(
				String.format("%s:%d", attr.getHost(), attr.getPort()),
				pool);
	}

}
 
开发者ID:crosg,项目名称:Albianj2,代码行数:21,代码来源:AlbianRemoteUNIDService.java

示例11: doStart

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
    if (ObjectHelper.isEmpty(getNamedReplyTo())) {
        log.debug("No reply to destination is defined.  Using temporary destinations.");
    } else {
        log.debug("Using {} as the reply to destination.", getNamedReplyTo());
    }
    if (uuidGenerator == null) {
        // use the generator configured on the camel context
        uuidGenerator = getEndpoint().getCamelContext().getUuidGenerator();
    }
    if (consumers == null) {
        consumers = new GenericObjectPool<MessageConsumerResources>(new MessageConsumerResourcesFactory());
        consumers.setMaxActive(getConsumerCount());
        consumers.setMaxIdle(getConsumerCount());
        while (consumers.getNumIdle() < consumers.getMaxIdle()) {
            consumers.addObject();
        }
    }
    super.doStart();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:InOutProducer.java

示例12: openConnectionAndChannelPool

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
/**
 * Open connection and initialize channel pool
 * @throws Exception
 */
private synchronized void openConnectionAndChannelPool() throws Exception {
    log.trace("Creating connection...");
    this.conn = getEndpoint().connect(executorService);
    log.debug("Created connection: {}", conn);

    log.trace("Creating channel pool...");
    channelPool = new GenericObjectPool<Channel>(new PoolableChannelFactory(this.conn), getEndpoint().getChannelPoolMaxSize(),
            GenericObjectPool.WHEN_EXHAUSTED_BLOCK, getEndpoint().getChannelPoolMaxWait());
    if (getEndpoint().isDeclare()) {
        execute(new ChannelCallback<Void>() {
            @Override
            public Void doWithChannel(Channel channel) throws Exception {
                getEndpoint().declareExchangeAndQueue(channel);
                return null;
            }
        });
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:RabbitMQProducer.java

示例13: getPoolConfig

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
/**
 * 获取对象池配置
 * 
 * @return
 */
public GenericObjectPool.Config getPoolConfig() {
    GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
    // maxIdle为负数时,不对pool size大小做限制,此处做限制,防止保持过多空闲redis连接
    if (this.maxIdle >= 0) {
        poolConfig.maxIdle = this.maxIdle;
    }
    poolConfig.maxWait = this.maxWait;
    if (this.whenExhaustedAction >= 0 && this.whenExhaustedAction < 3) {
        poolConfig.whenExhaustedAction = this.whenExhaustedAction;
    }
    poolConfig.testOnBorrow = this.testOnBorrow;
    poolConfig.minIdle = this.minIdle;
    poolConfig.maxActive = this.maxActive;
    poolConfig.testOnReturn = this.testOnReturn;
    poolConfig.testWhileIdle = this.testWhileIdle;
    poolConfig.timeBetweenEvictionRunsMillis = this.timeBetweenEvictionRunsMillis;
    poolConfig.numTestsPerEvictionRun = this.numTestsPerEvictionRun;
    poolConfig.minEvictableIdleTimeMillis = this.minEvictableIdleTimeMillis;
    poolConfig.softMinEvictableIdleTimeMillis = this.softMinEvictableIdleTimeMillis;
    poolConfig.lifo = this.lifo;
    return poolConfig;
}
 
开发者ID:neoremind,项目名称:navi-pbrpc,代码行数:28,代码来源:PooledConfiguration.java

示例14: configureGenericObjectPool

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
protected void configureGenericObjectPool(GenericObjectPool genericObjectPool) throws SyslogRuntimeException {
	SyslogPoolConfigIF poolConfig = null;
	
	try {
		poolConfig = (SyslogPoolConfigIF) this.syslog.getConfig();
		
	} catch (ClassCastException cce) {
		throw new SyslogRuntimeException("config must implement interface SyslogPoolConfigIF");
	}
	
	genericObjectPool.setMaxActive(poolConfig.getMaxActive());
	genericObjectPool.setMaxIdle(poolConfig.getMaxIdle());
	genericObjectPool.setMaxWait(poolConfig.getMaxWait());
	genericObjectPool.setMinEvictableIdleTimeMillis(poolConfig.getMinEvictableIdleTimeMillis());
	genericObjectPool.setMinIdle(poolConfig.getMinIdle());
	genericObjectPool.setNumTestsPerEvictionRun(poolConfig.getNumTestsPerEvictionRun());
	genericObjectPool.setSoftMinEvictableIdleTimeMillis(poolConfig.getSoftMinEvictableIdleTimeMillis());
	genericObjectPool.setTestOnBorrow(poolConfig.isTestOnBorrow());
	genericObjectPool.setTestOnReturn(poolConfig.isTestOnReturn());
	genericObjectPool.setTestWhileIdle(poolConfig.isTestWhileIdle());
	genericObjectPool.setTimeBetweenEvictionRunsMillis(poolConfig.getTimeBetweenEvictionRunsMillis());
	genericObjectPool.setWhenExhaustedAction(poolConfig.getWhenExhaustedAction());
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:24,代码来源:GenericSyslogPoolFactory.java

示例15: setUp

import org.apache.commons.pool.impl.GenericObjectPool; //导入依赖的package包/类
protected void setUp() throws Exception {

        mockFactory = new Mock(PoolableObjectFactory.class);
        factory = (PoolableObjectFactory)mockFactory.proxy();
        
        pool = new GenericObjectPool(factory,
                1, // maxActive
                GenericObjectPool.WHEN_EXHAUSTED_BLOCK, // whenExhaustedAction
                60000, // maxWait (millis)
                1, // maxIdle
                true, // testOnBorrow
                false // testOnReturn
                );
        
        super.setUp();
    }
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:GenericObjectPoolTest.java


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