java.sql.SQLException:连接已关闭
我们正在获取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>
可能是我们缺少导致问题的某些配置或属性。
请建议任何其他库来解决此问题或帮助找出根本原因。
提前致谢。
回答:
以下配置对我有用
<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" />
此处的关键值是 。您当前使用的工厂具有默认超时,此后它将强制关闭会话。
上面的连接超时值对我有用,对于您的应用程序场景,您必须做一些尝试才能获得正确的值。
以上是 java.sql.SQLException:连接已关闭 的全部内容, 来源链接: utcz.com/qa/433774.html








