jfinal使用druid插件问题

不知道为什么使用druid插件.虽然效率挺高的但是总会报这个错.使用c3p0的就不会.这个问题一直没解决.有关报错信息和配置信息都截图出来.麻烦波总帮我看下.怎么配置才不会出问题.如果用初始化配置的话,问题还更多.

image.png

image.png

评论区

JFinal

2018-10-19 16:46

异常信息没有提供 cause 部分, 猜不到

JM-java

2018-10-19 17:07

com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: connection holder is null
at com.jfinal.plugin.activerecord.DbPro.query(DbPro.java:109)
at com.jfinal.plugin.activerecord.DbPro.queryColumn(DbPro.java:154)
at com.jfinal.plugin.activerecord.DbPro.queryNumber(DbPro.java:280)
at com.jfinal.plugin.activerecord.DbPro.queryLong(DbPro.java:187)
at com.jfinal.plugin.activerecord.DbPro.queryLong(DbPro.java:192)
at com.jfinal.plugin.activerecord.Db.queryLong(Db.java:144)
at com.renxi.core.controller.AppController.getJudgeAddMessage(AppController.java:153)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
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.renxi.core.interceptor.MyInterceptor.doIntercept(MyInterceptor.java:34)
at com.jfinal.aop.PrototypeInterceptor.intercept(PrototypeInterceptor.java:26)
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:83)
at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:81)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:610)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:503)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.sql.SQLException: connection holder is null
at com.alibaba.druid.pool.DruidPooledConnection.checkStateInternal(DruidPooledConnection.java:1140)
at com.alibaba.druid.pool.DruidPooledConnection.checkState(DruidPooledConnection.java:1131)
at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:333)
at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.jfinal.plugin.activerecord.SqlReporter.invoke(SqlReporter.java:58)
at com.sun.proxy.$Proxy6.prepareStatement(Unknown Source)
at com.jfinal.plugin.activerecord.DbPro.query(DbPro.java:78)
at com.jfinal.plugin.activerecord.DbPro.query(DbPro.java:107)
... 30 more

JFinal

2018-10-19 17:24

DruidPlugin 有一个配置 : DruidPlugin.setRemoveAbandoned(false)

默认值不会出这个问题,你应该是改了这个默认,改默认也可以,使用这个方法将值调大:
DruidPlugin.setRemoveAbandonedTimeoutMillis(3 * 60 * 60 * 60 * 1000)
调成上面的 3 个小时,当然这个只是示例,具体调成多少你自己根据需求决定

这个配置的含义在 DruidPlugin 中有说明:
// 是否打开连接泄露自动检测
private boolean removeAbandoned = false;
// 连接长时间没有使用,被认为发生泄露时长
private long removeAbandonedTimeoutMillis = 300 * 1000;

此外,搜索异常中的 cause 部分, 到处都是解决方案:
https://blog.csdn.net/lzwglory/article/details/73301886
https://blog.csdn.net/wo8553456/article/details/40396401
https://www.cnblogs.com/dimple91/p/9124653.html
http://blog.sina.com.cn/s/blog_544c72960102w2lm.html
http://timerbin.iteye.com/blog/2332995

JM-java

2018-10-23 16:19

@JFinal 波总,现在恢复默认设置了.但是仍然没法解决问题.现在配置除了最大活跃数,其他都是默认设置.不知道怎么处理了.
现在的配置就只有这些了.
DruidPlugin druidPlugin = createDruidPlugin();
druidPlugin.addFilter(new StatFilter());
WallFilter wall = new WallFilter();//防sql注入
wall.setDbType("mysql");
druidPlugin.addFilter(wall);
druidPlugin.setMaxActive(1200);
me.add(druidPlugin);

热门反馈

扫码入社