Postgres Spring数据JPA休眠中的间歇性关闭连接

时间:2019-09-16 07:11:33

标签: postgresql hibernate spring-boot jpa spring-data-jpa

我经常间歇性地遇到这个问题。

我们已经配置了

支持的Spring Boot项目
  1. spring-boot-starter-data-jpa(1.5.3.RELEASE),
  2. spring-data-jpa(1.11.3.RELEASE),
  3. hibernate-core(5.0.12.Final),
  4. org.postgresql:postgresql:9.4.1212.jre7
  5. org.apache.tomcat:tomcat-jdbc:8.5.14

postgres => SELECT version();

版本

PostgreSQL 11.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit

(1行)

org.apache.tomcat.jdbc.pool.DataSource是从包含以下数据源属性的application.yml中填充的

spring:
 tomcat:
  removeAbandoned: true
  removeAbandonedTimeout: 120
  logAbandoned: true
  maxActive: 50
  maxIdle: 5
  maxWait: 1000
  validationQuery: "select 1"
  testOnBorrow: true
  testOnConnect: true
  testWhileIdle: true

我们间歇性地遇到以下连接关闭问题,当我们重新启动服务时,该问题已得到纠正。

org.postgresql.util.PSQLException: This connection has been closed.
    at org.postgresql.jdbc.PgConnection.checkClosed(PgConnection.java:803)
    at org.postgresql.jdbc.PgConnection.rollback(PgConnection.java:810)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
    at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:79)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
    at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
    at com.sun.proxy.$Proxy101.rollback(Unknown Source)
    at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.rollback(AbstractLogicalConnectionImplementor.java:115)
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.rollback(JdbcResourceLocalTransactionCoordinatorImpl.java:250)
    at org.hibernate.engine.transaction.internal.TransactionImpl.rollback(TransactionImpl.java:89)
    at org.hibernate.jpa.internal.TransactionImpl.rollback(TransactionImpl.java:101)
    at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:544)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:853)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:830)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:522)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:286)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) 

我发现以下问题无用Intermittent Java PostgreSQL Connection closed

对此将提供任何帮助。

0 个答案:

没有答案