Open subrahmanyam6969 opened 5 years 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();
}
}
}
Environment
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