使用JFinal默认的连接池连接Oracle,在空闲一段时间后,会断开连接。

使用JFinal默认的连接池连接Oracle,在空闲一段时间后,会断开连接。后台报如下错误:

[ERROR]-[Thread: http-nio-7024-exec-10]-[com.alibaba.druid.util.JdbcUtils.close()]: close statement error
java.sql.SQLRecoverableException: 关闭的连接
	at oracle.jdbc.driver.PhysicalConnection.needLine(PhysicalConnection.java:5389)
	at oracle.jdbc.driver.OracleStatement.closeOrCache(OracleStatement.java:1578)
	at oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:1563)
	at oracle.jdbc.driver.OracleStatementWrapper.close(OracleStatementWrapper.java:94)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2386)
	at com.alibaba.druid.filter.stat.StatFilter.statement_close(StatFilter.java:311)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2383)
	at com.alibaba.druid.filter.FilterAdapter.statement_close(FilterAdapter.java:2447)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2383)
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.close(StatementProxyImpl.java:124)
	at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:92)
	at com.alibaba.druid.pool.DruidAbstractDataSource.testConnectionInternal(DruidAbstractDataSource.java:1259)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:928)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
	at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.filter.FilterAdapter.dataSource_getConnection(FilterAdapter.java:2724)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:880)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)
	at com.jfinal.plugin.activerecord.Config.getConnection(Config.java:203)
	at com.jfinal.plugin.activerecord.Model.find(Model.java:583)
	at com.jfinal.plugin.activerecord.Model.findFirst(Model.java:606)
	at com.zshsoft.yshis.web.db.model.BaseModel.doFindFirst(BaseModel.java:354)
	at com.zshsoft.yshis.web.db.model.BaseModel.doFindFirst(BaseModel.java:368)
	at com.zshsoft.yshis.service.system.KW05Service.login(KW05Service.java:35)
	at com.zshsoft.yshis.controller.login.MedicalLoginController.login(MedicalLoginController.java:32)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
	at com.zshsoft.yshis.web.intercept.LoginInterceptor.intercept(LoginInterceptor.java:57)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.zshsoft.yshis.web.intercept.ThreadLocalIntercept.intercept(ThreadLocalIntercept.java:29)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:91)
	at com.zshsoft.yshis.web.handler.BasePathHandler.handle(BasePathHandler.java:35)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:722)

2018-03-16 21:56:29
[ERROR]-[Thread: http-nio-7024-exec-3]-[com.alibaba.druid.util.JdbcUtils.close()]: close statement error
java.sql.SQLRecoverableException: 关闭的连接
	at oracle.jdbc.driver.PhysicalConnection.needLine(PhysicalConnection.java:5389)
	at oracle.jdbc.driver.OracleStatement.closeOrCache(OracleStatement.java:1578)
	at oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:1563)
	at oracle.jdbc.driver.OracleStatementWrapper.close(OracleStatementWrapper.java:94)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2386)
	at com.alibaba.druid.filter.stat.StatFilter.statement_close(StatFilter.java:311)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2383)
	at com.alibaba.druid.filter.FilterAdapter.statement_close(FilterAdapter.java:2447)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2383)
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.close(StatementProxyImpl.java:124)
	at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:92)
	at com.alibaba.druid.pool.DruidAbstractDataSource.testConnectionInternal(DruidAbstractDataSource.java:1259)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:928)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
	at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.filter.FilterAdapter.dataSource_getConnection(FilterAdapter.java:2724)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:880)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)
	at com.jfinal.plugin.activerecord.Config.getConnection(Config.java:203)
	at com.jfinal.plugin.activerecord.Model.find(Model.java:583)
	at com.jfinal.plugin.activerecord.Model.findFirst(Model.java:606)
	at com.zshsoft.yshis.web.db.model.BaseModel.doFindFirst(BaseModel.java:354)
	at com.zshsoft.yshis.web.db.model.BaseModel.doFindFirst(BaseModel.java:368)
	at com.zshsoft.yshis.service.system.KW05Service.login(KW05Service.java:35)
	at com.zshsoft.yshis.controller.login.MedicalLoginController.login(MedicalLoginController.java:32)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
	at com.zshsoft.yshis.web.intercept.LoginInterceptor.intercept(LoginInterceptor.java:57)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.zshsoft.yshis.web.intercept.ThreadLocalIntercept.intercept(ThreadLocalIntercept.java:29)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:91)
	at com.zshsoft.yshis.web.handler.BasePathHandler.handle(BasePathHandler.java:35)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:722)

2018-03-16 21:56:37
[ERROR]-[Thread: http-nio-7024-exec-10]-[com.alibaba.druid.util.JdbcUtils.close()]: close statement error
java.sql.SQLRecoverableException: 关闭的连接
	at oracle.jdbc.driver.PhysicalConnection.needLine(PhysicalConnection.java:5389)
	at oracle.jdbc.driver.OracleStatement.closeOrCache(OracleStatement.java:1578)
	at oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:1563)
	at oracle.jdbc.driver.OracleStatementWrapper.close(OracleStatementWrapper.java:94)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2386)
	at com.alibaba.druid.filter.stat.StatFilter.statement_close(StatFilter.java:311)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2383)
	at com.alibaba.druid.filter.FilterAdapter.statement_close(FilterAdapter.java:2447)
	at com.alibaba.druid.filter.FilterChainImpl.statement_close(FilterChainImpl.java:2383)
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.close(StatementProxyImpl.java:124)
	at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:92)
	at com.alibaba.druid.pool.DruidAbstractDataSource.testConnectionInternal(DruidAbstractDataSource.java:1259)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:928)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
	at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.filter.FilterAdapter.dataSource_getConnection(FilterAdapter.java:2724)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:880)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)
	at com.jfinal.plugin.activerecord.Config.getConnection(Config.java:203)
	at com.jfinal.plugin.activerecord.Model.find(Model.java:583)
	at com.jfinal.plugin.activerecord.Model.findFirst(Model.java:606)
	at com.zshsoft.yshis.web.db.model.BaseModel.doFindFirst(BaseModel.java:354)
	at com.zshsoft.yshis.web.db.model.BaseModel.doFindFirst(BaseModel.java:368)
	at com.zshsoft.yshis.service.system.KW05Service.login(KW05Service.java:35)
	at com.zshsoft.yshis.controller.login.MedicalLoginController.login(MedicalLoginController.java:32)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
	at com.zshsoft.yshis.web.intercept.LoginInterceptor.intercept(LoginInterceptor.java:57)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.zshsoft.yshis.web.intercept.ThreadLocalIntercept.intercept(ThreadLocalIntercept.java:29)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)
	at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:91)
	at com.zshsoft.yshis.web.handler.BasePathHandler.handle(BasePathHandler.java:35)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:722)

需要好几秒甚至几分钟才能重新连接上。Oracle连接配置如下:

                System.setProperty("oracle.jdbc.V8Compatible", "true");
		DruidPlugin druidPlugin = getDruidPlugin();

		wallFilter = new WallFilter();
		wallFilter.setDbType("oracle");
		druidPlugin.addFilter(wallFilter);
		druidPlugin.addFilter(new StatFilter());
		druidPlugin.setValidationQuery("SELECT 1 FROM DUAL");

		me.add(druidPlugin);
		ActiveRecordPlugin atbp = new ActiveRecordPlugin(druidPlugin);
		atbp.setShowSql(p.getBoolean("oracle.showSql", false));

请问@JFinal或者其他大神有遇到过类似的情况吗?有没有好的解决办法?

评论区

JFinal

2018-03-17 11:08

去掉这一行试试:
druidPlugin.setValidationQuery("SELECT 1 FROM DUAL");

我记得 DruidPlugin为 validation 给过默认配置,或许你的配置覆盖掉默认配置后反而不正常

奋斗的小健健

2018-07-12 10:09

你好,我也发现了这个问题,最后怎么解决的?我的oracle是第二数据源,第一次能连接,等待几分钟就连不上了,然后报connection holder is null

buerxuezai

2019-08-06 09:51

楼主问题解决没~急

热门反馈

扫码入社