當前位置: 首頁>>代碼示例>>Java>>正文


Java GenericObjectPool.WHEN_EXHAUSTED_BLOCK屬性代碼示例

本文整理匯總了Java中org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_BLOCK屬性的典型用法代碼示例。如果您正苦於以下問題:Java GenericObjectPool.WHEN_EXHAUSTED_BLOCK屬性的具體用法?Java GenericObjectPool.WHEN_EXHAUSTED_BLOCK怎麽用?Java GenericObjectPool.WHEN_EXHAUSTED_BLOCK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.commons.pool.impl.GenericObjectPool的用法示例。


在下文中一共展示了GenericObjectPool.WHEN_EXHAUSTED_BLOCK屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: openConnectionAndChannelPool

/**
 * 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,代碼行數:22,代碼來源:RabbitMQProducer.java

示例2: setUp

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,代碼行數:16,代碼來源:GenericObjectPoolTest.java

示例3: preparePool

@Override
public void preparePool() throws Exception {
  pool = new org.apache.commons.pool.impl.GenericObjectPool<>(
      new MyPoolableObjectFactory(),
      poolSize,
      GenericObjectPool.WHEN_EXHAUSTED_BLOCK,
      GenericObjectPool.DEFAULT_MAX_WAIT,
      GenericObjectPool.DEFAULT_MAX_IDLE,
      GenericObjectPool.DEFAULT_MIN_IDLE,
      true, // test on borrow
      false,
      GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
      GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
      GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
      false,
      GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
      GenericObjectPool.DEFAULT_LIFO);
}
 
開發者ID:chrisvest,項目名稱:object-pool-benchmarks,代碼行數:18,代碼來源:ClaimRelease.java

示例4: createPool

private GenericObjectPool<Channel> createPool(Location loc, int active) {
  GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
  poolConfig.maxActive = active * 5;
  poolConfig.maxWait = 30000;
  poolConfig.maxIdle = active * 5;
  poolConfig.minIdle = active;
  poolConfig.testOnBorrow = false;
  poolConfig.testOnReturn = false;
  poolConfig.minEvictableIdleTimeMillis = Integer.MAX_VALUE;
  poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
  return new GenericObjectPool<Channel>(new ChannelObjectFactory(loc, bootstrap), poolConfig);
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:12,代碼來源:ChannelManager.java

示例5: NormalizerPool

private NormalizerPool(Set<CHECKType> exclusions, boolean errorAsWarning)
{
   Config poolcfg = new Config();
   poolcfg.maxIdle = 3;
   poolcfg.maxActive = 20;
   poolcfg.timeBetweenEvictionRunsMillis = 1000 * 3600;
   poolcfg.testWhileIdle = true;
   // since we do not set maxActive for the moment this does not matter
   poolcfg.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
   poolcfg.maxWait = 40000;
   NormalizerFactory fact = new NormalizerFactory(exclusions, errorAsWarning);

   pool = new GenericObjectPool(fact, poolcfg);
}
 
開發者ID:chemalot,項目名稱:chemalot,代碼行數:14,代碼來源:NormalizerPool.java

示例6: whenExhaustedAction

protected byte whenExhaustedAction(int maxActive, int maxWait) {
    byte whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
    if (maxActive <= 0) {
        whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    } else if (maxWait == 0) {
        whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
    }
    return whenExhausted;
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:9,代碼來源:InstanceKeyDataSource.java

示例7: setUp

public void setUp() throws Exception {
    super.setUp();
    GenericObjectPool pool = new GenericObjectPool(null, getMaxActive(), GenericObjectPool.WHEN_EXHAUSTED_BLOCK, getMaxWait(), 10, true, true, 10000L, 5, 5000L, true);
    DriverConnectionFactory cf = new DriverConnectionFactory(new TesterDriver(),"jdbc:apache:commons:testdriver",null);
    GenericKeyedObjectPoolFactory opf = new GenericKeyedObjectPoolFactory(null, 10, GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, 2000L, 10, true, true, 10000L, 5, 5000L, true);
    PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, pool, opf, "SELECT COUNT(*) FROM DUAL", false, true);
    assertNotNull(pcf);
    driver = new PoolingDriver();
    driver.registerPool("test",pool);
    PoolingDriver.setAccessToUnderlyingConnectionAllowed(true);
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:11,代碼來源:TestManual.java

示例8: testReportedBug12400

/** @see "http://issues.apache.org/bugzilla/show_bug.cgi?id=12400" */
public void testReportedBug12400() throws Exception {
    ObjectPool connectionPool = new GenericObjectPool(
        null,
        70,
        GenericObjectPool.WHEN_EXHAUSTED_BLOCK,
        60000,
        10);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
        "jdbc:apache:commons:testdriver", 
        "username", 
        "password");
    PoolableConnectionFactory poolableConnectionFactory = 
        new PoolableConnectionFactory(
            connectionFactory,
            connectionPool,
            null,
            null,
            false,
            true);
    assertNotNull(poolableConnectionFactory);
    PoolingDriver driver2 = new PoolingDriver();
    driver2.registerPool("neusoftim",connectionPool);
    Connection[] conn = new Connection[25];
    for(int i=0;i<25;i++) {
        conn[i] = DriverManager.getConnection("jdbc:apache:commons:dbcp:neusoftim");
        for(int j=0;j<i;j++) {
            assertTrue(conn[j] != conn[i]);
            assertTrue(!conn[j].equals(conn[i]));
        }
    }
    for(int i=0;i<25;i++) {
        conn[i].close();
    }
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:35,代碼來源:TestManual.java

示例9: testDriverManagerInit

public void testDriverManagerInit() throws Exception {
    System.setProperty("jdbc.drivers",
            "org.apache.commons.dbcp.TesterDriver");
    GenericObjectPool connectionPool = new GenericObjectPool(null, 10,
            GenericObjectPool.WHEN_EXHAUSTED_BLOCK, -1, 0);
    final ConnectionFactory connectionFactory =
        new DriverManagerConnectionFactory(
                "jdbc:apache:commons:testdriver",
                "foo", "bar");
    final PoolableConnectionFactory poolableConnectionFactory =
        new PoolableConnectionFactory(connectionFactory, connectionPool,
                null, null, false, true);
    connectionPool.setFactory(poolableConnectionFactory);
    PoolingDataSource dataSource =
        new PoolingDataSource(connectionPool);

    ConnectionThread[] connectionThreads = new ConnectionThread[10];
    Thread[] threads = new Thread[10];
    
    for (int i = 0; i < 10; i++) {
        connectionThreads[i] = new ConnectionThread(dataSource);
        threads[i] = new Thread(connectionThreads[i]);
    }
    for (int i = 0; i < 10; i++) {
        threads[i].start();
    }
    for (int i = 0; i < 10; i++) {
        while (threads[i].isAlive()){//JDK1.5: getState() != Thread.State.TERMINATED) {
            Thread.sleep(100);
        }
        if (!connectionThreads[i].getResult()) {
            fail("Exception during getConnection");
        }
    }
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:35,代碼來源:TestDriverManagerConnectionFactory.java

示例10: init

protected void init() {
  // store factory
  TopicMapStoreFactoryIF sfactory = new TopicMapStoreFactoryIF() {
    @Override
    public TopicMapStoreIF createStore() {
     return _createStore(false);
    }
  };

  // initialize pool
  this.ofactory = new StorePoolableObjectFactory(sfactory);
  this.pool = new GenericObjectPool(ofactory);
  this.pool.setTestOnBorrow(true);

  Map<String, String> properties = storage.getProperties();
  if (properties != null) {
    // Set minimum pool size (default: 0)
    String _minsize = PropertyUtils.getProperty(properties,
        "net.ontopia.topicmaps.impl.rdbms.StorePool.MinimumSize", false);
    int minsize = (_minsize == null ? 0 : Integer.parseInt(_minsize));
    log.debug("Setting StorePool.MinimumSize '" + minsize + "'");
    pool.setMinIdle(minsize); // 0 = no limit

    // Set maximum pool size (default: Integer.MAX_VALUE)
    String _maxsize = PropertyUtils.getProperty(properties,
        "net.ontopia.topicmaps.impl.rdbms.StorePool.MaximumSize", false);
    int maxsize = (_maxsize == null ? 8 : Integer.parseInt(_maxsize));
    log.debug("Setting StorePool.MaximumSize '" + maxsize + "'");
    pool.setMaxActive(maxsize); // 0 = no limit

    // Set soft maximum - emergency objects (default: false)
    boolean softmax = MapUtils.getBoolean(properties, "net.ontopia.topicmaps.impl.rdbms.StorePool.SoftMaximum", false);
    log.debug("Setting StorePool.SoftMaximum '" + softmax + "'");
    if (softmax)
      pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    else
      pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
    
    // EXPERIMENTAL!
    String _etime = PropertyUtils.getProperty(properties, "net.ontopia.topicmaps.impl.rdbms.StorePool.IdleTimeout", false);
    int etime = (_etime == null ? -1 : Integer.parseInt(_etime));
    pool.setTimeBetweenEvictionRunsMillis(etime);
    pool.setSoftMinEvictableIdleTimeMillis(etime);
  }

  // allow the user to fully overwrite exhausted options
  String _whenExhaustedAction = PropertyUtils.getProperty(properties, "net.ontopia.topicmaps.impl.rdbms.StorePool.WhenExhaustedAction", false);
  if (EXHAUSED_BLOCK.equals(_whenExhaustedAction))
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
  if (EXHAUSED_GROW.equals(_whenExhaustedAction))
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
  if (EXHAUSED_FAIL.equals(_whenExhaustedAction))
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL);

  if (pool.getWhenExhaustedAction() == GenericObjectPool.WHEN_EXHAUSTED_BLOCK)
    log.debug("Pool is set to block on exhaused");
  if (pool.getWhenExhaustedAction() == GenericObjectPool.WHEN_EXHAUSTED_GROW)
    log.debug("Pool is set to grow on exhaused");
  if (pool.getWhenExhaustedAction() == GenericObjectPool.WHEN_EXHAUSTED_FAIL)
    log.debug("Pool is set to fail on exhaused");

}
 
開發者ID:ontopia,項目名稱:ontopia,代碼行數:62,代碼來源:RDBMSTopicMapReference.java


注:本文中的org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_BLOCK屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。