GD Star Rating
loading...
loading...
仅需修改context.xml:
- <context path="/chinatrial">
- <resource
- name="jdbc/DBPool"
- type="javax.sql.DataSource"
- driverClassName="com.mysql.jdbc.Driver"
- maxIdle="16"
- minIdle="8"
- maxActive="64"
- initialSize="16"
- username="root"
- password="root"
- poolPreparedStatements="true"
- removeAbandoned="true"
- removeAbandonedTimeout="60"
- testOnBorrow="false "
- url="jdbc:mysql://localhost/chinatrial"
- connectionProperties="useUnicode=true;characterEncoding=utf-8;autoReconnect=true">
- </context>
<context path="/chinatrial">
<resource
name="jdbc/DBPool"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="16"
minIdle="8"
maxActive="64"
initialSize="16"
username="root"
password="root"
poolPreparedStatements="true"
removeAbandoned="true"
removeAbandonedTimeout="60"
testOnBorrow="false "
url="jdbc:mysql://localhost/chinatrial"
connectionProperties="useUnicode=true;characterEncoding=utf-8;autoReconnect=true">
</context>各属性的含义以及完整属性列表可参考:DBCP官方文档,以下是一些建议:
- 将连接属性配置在“ connectionProperties”中,这样可以避免对“&”符号进行转义
- 配置“poolPreparedStatements”以缓存PreparedStatement对象提升性能
- 配置“removeAbandoned”和“removeAbandonedTimeout”以打开“Remove Abandoned Connection”功能。该功能会定期检查并关闭没有被close的connection,避免连接泄
- 将“testOnBorrow”设为“false”以关闭从连接池获取连接时的有效性检查
原创内容,转载请注明: 转载自拈花微笑
本文链接地址: 如何配置Tomcat数据库连接池
