Search in sources :

Example 11 with ConnectionPool

use of org.apache.tomcat.jdbc.pool.ConnectionPool in project platformlayer by platformlayer.

the class TomcatJdbcPoolMetricsReporter method addMetrics.

@Override
public void addMetrics(MetricTreeObject tree) {
    ConnectionPool pool = getPool();
    if (pool == null) {
        // TODO: Should we handle this properly??
        return;
    }
    MetricTreeObject subtree = tree.getSubtree(key);
    // Statistics stats = pool.getStatistics();
    // subtree.addInt("hitCount", stats.getCacheHits());
    // subtree.addInt("missCount", stats.getCacheMiss());
    // subtree.addInt("connectionsRequested", stats.getConnectionsRequested());
    // subtree.addInt("statementsCached", stats.getStatementsCached());
    // subtree.addInt("statementsExecuted", stats.getStatementsExecuted());
    // subtree.addInt("statementsPrepared", stats.getStatementsPrepared());
    // subtree.addInt("cumulativeConnectionWaitTime", stats.getCumulativeConnectionWaitTime());
    // subtree.addInt("cumulativeStatementExecutionTime", stats.getCumulativeStatementExecutionTime());
    // subtree.addInt("cumulativeStatementPrepareTime", stats.getCumulativeStatementPrepareTime());
    //
    subtree.addInt("activeConnections", pool.getActive());
    subtree.addInt("idleConnections", pool.getIdle());
    subtree.addInt("waitCount", pool.getWaitCount());
}
Also used : ConnectionPool(org.apache.tomcat.jdbc.pool.ConnectionPool)

Example 12 with ConnectionPool

use of org.apache.tomcat.jdbc.pool.ConnectionPool in project tomee by apache.

the class TomEEDataSourceCreator method pool.

@Override
public DataSource pool(final String name, final DataSource ds, final Properties properties) {
    final PoolConfiguration config = build(TomEEPoolProperties.class, createProperties(name, properties));
    config.setDataSource(ds);
    final ConnectionPool pool;
    try {
        pool = new ConnectionPool(config);
    } catch (final SQLException e) {
        throw new IllegalStateException(e);
    }
    final TomEEDataSource dataSource = new TomEEDataSource(config, pool, name);
    // transfer unset props for correct logging
    recipes.put(dataSource, recipes.remove(config));
    return dataSource;
}
Also used : ConnectionPool(org.apache.tomcat.jdbc.pool.ConnectionPool) PoolConfiguration(org.apache.tomcat.jdbc.pool.PoolConfiguration) SQLException(java.sql.SQLException)

Example 13 with ConnectionPool

use of org.apache.tomcat.jdbc.pool.ConnectionPool in project dal by ctripcorp.

the class DefaultDataSourceTerminateTask method closeTomcatDataSource.

private boolean closeTomcatDataSource() {
    boolean success = true;
    LOGGER.info(String.format("Error retry times for datasource %s:%s", name, retryTimes));
    int abandonedTimeout = getAbandonedTimeout();
    LOGGER.info(String.format("Abandoned timeout for datasource %s:%s", name, abandonedTimeout));
    int elapsedSeconds = getElapsedSeconds();
    LOGGER.info(String.format("Elapsed seconds for datasource %s:%s", name, elapsedSeconds));
    org.apache.tomcat.jdbc.pool.DataSource ds = (org.apache.tomcat.jdbc.pool.DataSource) dataSource;
    if (retryTimes > MAX_RETRY_TIMES) {
        LOGGER.info(String.format("Force closing datasource %s,retry times:%s,max retry times:%s.", name, retryTimes, MAX_RETRY_TIMES));
        ds.close(true);
        isForceClosing = true;
        return success;
    } else if (elapsedSeconds >= abandonedTimeout) {
        LOGGER.info(String.format("Force closing datasource %s,elapsed seconds:%s,abandoned timeout:%s.", name, elapsedSeconds, abandonedTimeout));
        ds.close(true);
        isForceClosing = true;
        return success;
    }
    ConnectionPool pool = ds.getPool();
    if (pool == null)
        return success;
    int idle = pool.getIdle();
    if (idle > 0) {
        pool.purge();
        LOGGER.info(String.format("Idle connections of datasource %s have been closed.", name));
    }
    int active = pool.getActive();
    if (active == 0) {
        ds.close();
        LOGGER.info(String.format("Active connections of datasource %s is zero, datasource has been closed.", name));
    } else if (active > 0) {
        LOGGER.info(String.format("Active connections of datasource %s is %s.", name, active));
        success = false;
    }
    return success;
}
Also used : ConnectionPool(org.apache.tomcat.jdbc.pool.ConnectionPool) DataSource(javax.sql.DataSource)

Aggregations

ConnectionPool (org.apache.tomcat.jdbc.pool.ConnectionPool)13 Connection (java.sql.Connection)7 Test (org.junit.Test)7 CallableStatement (java.sql.CallableStatement)5 Statement (java.sql.Statement)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 PoolConfiguration (org.apache.tomcat.jdbc.pool.PoolConfiguration)3 SlowQueryReport (org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport)3 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DataSource (org.apache.tomcat.jdbc.pool.DataSource)2 PoolProperties (org.apache.tomcat.jdbc.pool.PoolProperties)2 DefaultProperties (org.apache.tomcat.jdbc.test.DefaultProperties)2 AbstractConnectionListener (com.ctrip.platform.dal.dao.datasource.AbstractConnectionListener)1 DalConnectionPool (com.ctrip.platform.dal.dao.datasource.tomcat.DalConnectionPool)1 DalTomcatDataSource (com.ctrip.platform.dal.dao.datasource.tomcat.DalTomcatDataSource)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 Hashtable (java.util.Hashtable)1