java.sql.SQLException: 连接已经关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31941889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.sql.SQLException: Connection has already been closed
提问by Mukesh Kumar
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.
我们收到 java.sql.SQLException: 连接已经关闭。执行事务时间歇性异常。我们使用的是tomcat 7.X,以下是配置。
<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.
请建议任何其他库来解决此问题或帮助找出根本原因。
Thanks in advance.
提前致谢。
采纳答案by puneet goyal
Following configuration worked for me
以下配置对我有用
<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" />
The key value here is connectionTimeout. The factory which you are currently using has a default timeout, after that it forces session to close.
这里的关键值是connectionTimeout。您当前使用的工厂有一个默认超时,之后它会强制关闭会话。
The connection timeout value above worked for me , for your application scenarios you'll have to experiment a bit to get the right value.
上面的连接超时值对我有用,对于您的应用程序场景,您必须进行一些试验才能获得正确的值。
回答by alireza ranjbaran
add below value:
添加以下值:
removeAbandonedTimeout="600"