JDBI(不是JDBC)连接已关闭 - 如何处理

时间:2015-12-17 15:43:37

标签: java postgresql jdbi

这是一个JDBI问题,Jarrod Roberson,不只是一个Postgres问题。)

我有一个业务类多次调用DAO方法。大约15分钟后,死于Postgres的连接关闭错误。

! Caused by: org.postgresql.util.PSQLException: This connection has been closed.
! at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:853) ~[hui-populator.jar:0.0.180]
! at org.postgresql.jdbc2.AbstractJdbc2Connection.rollback(AbstractJdbc2Connection.java:870) ~[hui-populator.jar:0.0.180]
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
! at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
! at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126) ~[hui-populator.jar:0.0.180]
! at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109) ~[hui-populator.jar:0.0.180]
! at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80) ~[hui-populator.jar:0.0.180]
! at com.sun.proxy.$Proxy39.rollback(Unknown Source) ~[na:na]
! at org.skife.jdbi.v2.tweak.transactions.LocalTransactionHandler.rollback(LocalTransactionHandler.java:90) ~[hui-populator.jar:0.0.180]
! ... 62 common frames omitted

这是Dao类的实例化方式:

final DBI jdbi = factory.build(environment, configuration.getHuiDbDatabase(), "postgres");

    final MyDao myDao = jdbi.onDemand(MyDao.class);

A然后这个dao有一个使用@Transaction注释的方法,该方法从业务类中多次调用。

在某些时候连接已关闭。我应该怎么做才能处理它,以便我可以继续调用@Transaction方法?

0 个答案:

没有答案