コード例 #1
0
  /** Clears the idle connections in the pool. */
  @Override
  public void clear() {
    ArrayList<ManagedPoolItem> pool = _connectionPool;

    if (pool == null) return;

    ArrayList<ManagedPoolItem> clearItems = new ArrayList<ManagedPoolItem>();

    synchronized (_connectionPool) {
      _idlePool.clear();

      clearItems.addAll(pool);

      pool.clear();
    }

    for (int i = 0; i < clearItems.size(); i++) {
      ManagedPoolItem poolItem = clearItems.get(i);

      try {
        poolItem.destroy();
      } catch (Throwable e) {
        log.log(Level.WARNING, e.toString(), e);
      }
    }
  }
コード例 #2
0
  /** Alarm listener. */
  @Override
  public void handleAlarm(Alarm alarm) {
    if (!_lifecycle.isActive()) return;

    try {
      _alarmConnections.clear();

      synchronized (_connectionPool) {
        _alarmConnections.addAll(_connectionPool);
      }

      for (int i = _alarmConnections.size() - 1; i >= 0; i--) {
        ManagedPoolItem item = _alarmConnections.get(i);

        if (!item.isValid()) item.destroy();
      }

      _alarmConnections.clear();

      fillIdlePool();
    } finally {
      if (!_lifecycle.isActive()) {
      } else if (0 < _idleTimeout && _idleTimeout < 1000) _alarm.queue(1000);
      else if (1000 < _idleTimeout && _idleTimeout < 60000) _alarm.queue(_idleTimeout);
      else _alarm.queue(60000);
    }
  }