JDBC connection pool with the best performance: HikariCP, jdbchikaricp
HikariCP claims to be the best-performing JDBC connection pool component. I have not carefully tested the specific performance, but from the perspective of its development, it may indeed have higher performance than all current connection pool components as it promotes. Previously, the memory for the connection pool has always been C3P0, DBCP, and BoneCP. Among the three, BoneCP has the best performance. The performance of C3P0 is indeed very poor, it seems that C3P0 has not been updated for a long time, so we should stop using C3P0 In the project. As for whether to use HikariCP, I think we can try it. HikariCP is only available soon after all, and its performance also needs to be tested in practice. If you are worried about the pitfalls of new things, I recommend BoneCP. Spring is now integrated with HikariCP, so I think it is necessary to try it. Not long ago I used HikariCP in the project, and there was no problem, and the operation was stable.
Address of HikariCP on github: https://github.com/brettwooldridge/HikariCP
The following is a comparison of the performance of two HikariCP and other connection pool components:
You can see detailed usage documents on its website. The following is a general usage method:
Import java. SQL. connection; import java. SQL. SQLException; import com. zaxxer. hikari. hikariConfig; import com. zaxxer. hikari. hikariDataSource;/*** HikariCP use * @ author CoolKing **/public class DataSource {private HikariDataSource ds; /*** initialize the connection pool * @ param minimum * @ param Maximum */public void init (int minimum, int Maximum) {// configure HikariConfig config = new HikariConfig () in the connection pool (); config. setDriverClassName ("com. my SQL. jdbc. Driver "); config. setJdbcUrl (" jdbc: mysql: // 127.0.0.1: 3306/testdb? User = root & password = 123456 & useUnicode = true & characterEncoding = utf8 "); config. addDataSourceProperty ("cacheprepsponts", true); config. addDataSourceProperty ("prepStmtCacheSize", 500); config. addeffecceproperty ("prepStmtCacheSqlLimit", 2048); config. setConnectionTestQuery ("SELECT 1"); config. setAutoCommit (true); // the minimum number of idle connections in the pool config. setMinimumIdle (minimum); // The maximum number of connections in the pool config. setMaximumPoolSize (Maximum); ds = new HikariDataSource (config);}/*** destroy connection pool */public void shutdown () {ds. shutdown ();}/*** get the link from the Connection pool * @ return */public Connection getConnection () {try {return ds. getConnection ();} catch (SQLException e) {e. printStackTrace (); ds. resumePool (); return null ;}} public static void main (String [] args) throws SQLException {DataSource ds = new DataSource (); ds. init (10, 50); Connection conn = ds. getConnection ();//...... // close the link conn. close ();}}
In addition, HikariCP depends on the following jar files:
Slf4j-api-1.7.12.jar
Metrics-core-3.0.2.jar
Metrics-healthchecks-3.1.2.jar
Javassist-3.19.0-GA.jar
HikariCP-2.3.5.jar
Mysql-connector-java-5.0.8-bin.jar is also required if MySQL is used
You can download the jar from http://download.csdn.net/detail/abc_key/8790543.