高性能JDBC连接池:HikariCP
jopen
11年前
HikariCP 是一个高性能,“零开销”,高品质的 JDBC 连接池。下图是性能的比较测试结果:
使用方法:
HikariConfig config = new HikariConfig(); config.setMaximumPoolSize(100); config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); config.addDataSourceProperty("serverName", "localhost"); config.addDataSourceProperty("port", "3306"); config.addDataSourceProperty("databaseName", "mydb"); config.addDataSourceProperty("user", "bart"); config.addDataSourceProperty("password", "51mp50n"); HikariDataSource ds = new HikariDataSource(config);
或者:
/** connectionTestQuery=SELECT 1 dataSourceClassName=org.postgresql.ds.PGSimpleDataSource dataSource.user=test dataSource.password=test dataSource.databaseName=mydb dataSource.serverName=localhost */ HikariConfig config = new HikariConfig("some/path/hikari.properties"); HikariDataSource ds = new HikariDataSource(config);
Maven:
<dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>1.3.5</version> <scope>compile</scope> </dependency>