Using HIkariCP in spring MVC project

Keywords: Java JDBC MySQL xml Database

What is HIkariCP

https://www.jianshu.com/p/15b...

Using HikariCP data sources

pom.xml
<dependency>
  <groupId>com.zaxxer</groupId>
  <artifactId>HikariCP</artifactId>
  <version>3.3.1</version>
</dependency>
Spring-mvc.xml
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="shutdown">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="connectionTestQuery" value="SELECT 1" />
        <! -- effective timeout -- >
        <property name="validationTimeout" value="3000" />
        <! -- set to true when connecting to read-only database to ensure security -- >
        <property name="readOnly" value="false" />
        <! -- the maximum time (in milliseconds) to wait for the connection pool to allocate the connection. If the time is longer than this time and the connection is not available, SQLException will occur. Defau lt: 30 seconds -- >
        <property name="connectionTimeout" value="60000" />
        <! -- the maximum duration (MS) of a connection idle state, and the timeout will be released (retired). Defau lt: 10 minutes -- >
        <property name="idleTimeout" value="60000" />
        <! -- the lifetime of a connection (in milliseconds), which will be released if it is timeout and not used. Defau lt: 30 minutes. It is recommended to set it 30 seconds less than the database timeout. Refer to MySQL.
            Wait UU timeout parameter (show variables like '%timeout%';) -- >
        <property name="maxLifetime" value="60000" />
        <! -- the maximum number of connections allowed in the connection pool. Defau lt value: 10; recommended formula: ((core_count * 2) + effective_spice_count) -- >
        <property name="maximumPoolSize" value="10" />
    </bean>

Start success log

17:36:50.838 [main] WARN  com.zaxxer.hikari.HikariConfig - HikariPool-1 - idleTimeout has been set but has no effect because the pool is operating as a fixed size pool.
17:36:50.838 [main] DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery............."SELECT 1"
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............60000
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSource......................none
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
17:36:50.841 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - driverClassName................."com.mysql.jdbc.Driver"
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................60000
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:mysql://ykx.uerp.net:3306/ykx?useUnicode=true&characterEncoding=utf8
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................60000
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................10
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
17:36:50.843 [main] DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
17:36:50.844 [main] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
17:36:50.844 [main] DEBUG com.zaxxer.hikari.HikariConfig - schema..........................none
17:36:50.844 [main] DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
17:36:50.844 [main] DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
17:36:50.844 [main] DEBUG com.zaxxer.hikari.HikariConfig - username........................"ykx"
17:36:50.844 [main] DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............3000
17:36:50.844 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
17:36:51.257 [main] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection com.mysql.jdbc.JDBC4Connection@1d77a31d
17:36:51.260 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.

Posted by tomas.srna on Thu, 17 Oct 2019 12:08:19 -0700