druid校验连接超过15分钟

浩dan 发布于 01/09 14:57
阅读 450
收藏 0

Serverless 架构就不要服务器了?>>>

@yzChen233 你好,想跟你请教个问题:

老师您好:

        在用druid(1.1.5版本)作为impala的连接池过程中,发现连接长时间不用,等再次获取连接时校验连接是否有效花费了15分钟。

我的配置如下,testWhileIdle配置是true。看了druid的源码,发现报错的地方就是校验连接是否有效,我怀疑是connection已经断开,connection创建statement的时候耗时,请问老师是否有什么解决方案,希望得到您的回答,谢谢!

spring.datasource.initialSize=1
spring.datasource.minIdle=3
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=30000
spring.datasource.validationQuery=select 'x'
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.filters=stat,wall,slf4j
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

错误日志如下:

java.sql.SQLNonTransientConnectionException: [Simba][JDBC](10060) Connection has been closed.
        at com.cloudera.exceptions.ExceptionConverter.toSQLException(Unknown Source)
        at com.cloudera.jdbc.common.SConnection.closeConnection(Unknown Source)
        at com.cloudera.jdbc.common.SConnection.abortInternal(Unknown Source)
        at com.cloudera.jdbc.common.SConnection.close(Unknown Source)
        at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:73)
        at com.alibaba.druid.pool.DruidDataSource.discardConnection(DruidDataSource.java:1322)
        at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1287)

        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1221)
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1211)
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:105)
        at sun.reflect.GeneratedMethodAccessor132.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.sinolife.sf.trace.JdbcTracePlugin.openConnection(JdbcTracePlugin.java:174)
        at com.sinolife.sf.framework.dbcontext.DbSessionContextPlugin$1.invoke(DbSessionContextPlugin.java:279)
        at com.sun.proxy.$Proxy141.getConnection(Unknown Source)
        at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:371)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:415)
        at com.fd.offline.impala.service.Impl.ImpalaDBServiceImpl.refresh(ImpalaDBServiceImpl.java:49)
        at com.fd.offline.service.impl.ImpalaServiceImpl.refresh(ImpalaServiceImpl.java:164)
        at com.fd.offline.controller.ImpalaController.refresh(ImpalaController.java:82)
        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:497)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
        at com.fd.common.aspect.WebLogAspect.doAround(WebLogAspect.java:59)
        at sun.reflect.GeneratedMethodAccessor320.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
        at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at com.sinolife.sf.framework.controller.ControllerBrowserNoCacheMethodInterceptor.invoke(ControllerBrowserNoCacheMethodInterceptor.java:19)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

加载中
0
yzChen233
yzChen233

这个是我的配置,我仔细对比了,下你的配置比我的少一个 “druid” 成员属性,你改成下面发的再试试看吧。

spring.datasource.druid.initialSize=1
spring.datasource.druid.minIdle=3
spring.datasource.druid.maxActive=20
spring.datasource.druid.maxWait=60000
spring.datasource.druid.timeBetweenEvictionRunsMillis=60000
spring.datasource.druid.minEvictableIdleTimeMillis=30000
spring.datasource.druid.validationQuery=select 'x'
spring.datasource.druid.testWhileIdle=true
spring.datasource.druid.testOnBorrow=false
spring.datasource.druid.testOnReturn=false
spring.datasource.druid.poolPreparedStatements=true
spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.druid.filters=stat,wall,slf4j
spring.datasource.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
浩dan
浩dan
我试试,谢谢老师!
0
rxw4703
rxw4703

这个问题我遇到过,升级了版本

<druid.version>1.1.14</druid.version>

并添加了属性

<property name="keepAlive" value="true" />

就可以了

返回顶部
顶部