java.sql.SQLException:连接已关闭
我们收到java.sql.SQLException:Connection已经关闭。执行交易时间歇性地例外。我们使用的是tomcat 7.X,下面是配置。
We are getting java.sql.SQLException: Connection has already been closed. exception intermittently while performing a transaction. We are using tomcat 7.X and below is the configuration.
<Context docBase="ROOT" reloadable="true" antiJARLocking="true">
<Resource
name="jdbc/DS"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://XXXXXXX"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="XXXXXX"
password="XXXXXX"
maxActive="20"
maxIdle="3"
minIdle="3"
maxWait="10000"
removeAbandoned="true"/>
</Context>
可能我们在这里缺少导致问题的一些配置或属性。
Probably we are missing some configuration or property here that is causing the issue.
请建议任何其他图书馆来解决此问题或帮助找出根本原因。
Please suggest any other library to fix this issue or help to find out the root cause.
提前致谢。
以下配置为我工作
<Context context="ROOT" debug="0" reloadable="false" useHttpOnly="true" cacheMaxSize="40960" cacheTTL="60000" cachingAllowed="true" antiJARLocking="true">
<Resource name="XYZ" auth="Container"
description="Exchange DB Connection"
dataSourceClassName="org.postgresql.ds.PGSimpleDataSource"
dataSource.serverName="XXXXX"
dataSource.databaseName="XXXX"
dataSource.portNumber="XXXX"
dataSource.user="xyz"
dataSource.password="xyz"
maximumPoolSize="20"
minimumIdle="5"
connectionTimeout="300000"
factory="com.zaxxer.hikari.HikariJNDIFactory"
registerMbeans="true"
type="javax.sql.DataSource" />
这里的关键值是 connectionTimeout 即可。
您当前使用的工厂有一个默认超时,之后会强制关闭会话。
The key value here is connectionTimeout. The factory which you are currently using has a default timeout, after that it forces session to close.
上面的连接超时值对我有用,对于你来说应用场景,你必须尝试一下才能获得正确的值。
The connection timeout value above worked for me , for your application scenarios you'll have to experiment a bit to get the right value.