druid配置与HikariCP配置
druid配置
<bean id = "dataSource" class = "com.alibaba.druid.pool.DruidDataSource" destroy-method = "close" >
<!-- 数据库基本信息配置 -->
<property name = "url" value ="jdbc:mysql://localhost:3309/query?useUnicode=true&characterEncoding=utf-8" />
<property name ="username" value ="root" />
<property name = "password" value = "root" />
<property name = "driverClassName" value ="com.mysql.jdbc.Driver" />
<property name = "filters" value = "stat" />
<!-- 最大并发连接数 -->
<property name = "maxActive" value = "20" />
<!-- 初始化连接数量 -->
<property name = "initialSize" value = "1" />
<!-- 配置获取连接等待超时的时间 -->
<property name = "maxWait" value = "60000" />
<!-- 最小空闲连接数 -->
<property name = "minIdle" value = "10" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name = "timeBetweenEvictionRunsMillis" value ="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name = "minEvictableIdleTimeMillis" value ="300000" />
<property name = "validationQuery" value = "SELECT 'x'" />
<property name = "testWhileIdle" value = "true" />
<property name = "testOnBorrow" value = "false" />
<property name = "testOnReturn" value = "false" />
<property name = "maxOpenPreparedStatements" value ="20" />
<!-- 打开 removeAbandoned 功能 -->
<property name = "removeAbandoned" value = "true" />
<!-- 1800 秒,也就是 30 分钟 -->
<property name = "removeAbandonedTimeout" value ="1800" />
<!-- 关闭 abanded 连接时输出错误日志 -->
<property name = "logAbandoned" value = "true" />
</bean>
HikariCP配置
<!-- Hikari Datasource -->
<bean id="dataSourceHikari" class="com.zaxxer.hikari.HikariDataSource" destroy-method="shutdown">
<!-- <property name="driverClassName" value="${db.driverClass}" /> --> <!-- 无需指定,除非系统无法自动识别 -->
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<!-- 连接只读数据库时配置为true, 保证安全 -->
<property name="readOnly" value="false" />
<!-- 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 缺省:30秒 -->
<property name="connectionTimeout" value="30000" />
<!-- 一个连接idle状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟 -->
<property name="idleTimeout" value="600000" />
<!-- 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';) -->
<property name="maxLifetime" value="1800000" />
<!-- 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count) -->
<property name="maximumPoolSize" value="15" />
</bean>
更多推荐
所有评论(0)