brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
20.06k stars 2.95k forks source link

reaching max connections in tomcat not in websphere #1455

Open subrahmanyam6969 opened 5 years ago

subrahmanyam6969 commented 5 years ago

Environment

HikariCP version:2.2.5
JDK version     : 1.8.0_162
Database        : ORACLE
Driver version  : x.x.x

I have hikaricp configured for my application with oracle db. When I deploy my application to websphere and perform load test ,it is able to execute . but If i deploy application in tomcat It is reaching max connections taking longer time. please help

ljluestc commented 1 month ago

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class HikariCPExample {

    private static HikariDataSource dataSource;

    public static void main(String[] args) throws Exception {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:oracle:thin:@localhost:1521:orcl");
        config.setUsername("your_username");
        config.setPassword("your_password");
        config.setDriverClassName("oracle.jdbc.OracleDriver");
        config.setMinimumIdle(10);
        config.setMaximumPoolSize(50);
        config.setIdleTimeout(300000);
        config.setConnectionTimeout(30000);
        config.setMaxLifetime(1800000);
        config.setLeakDetectionThreshold(15000);

        dataSource = new HikariDataSource(config);

        try (Connection connection = dataSource.getConnection()) {
            PreparedStatement stmt = connection.prepareStatement("SELECT 1 FROM DUAL");
            ResultSet rs = stmt.executeQuery();
            if (rs.next()) {
                System.out.println("Query successful: " + rs.getInt(1));
            }
        } finally {
            dataSource.close();
        }
    }
}