Quartz和Druid如何配合使用?

Sokos 发布于 2013/07/31 19:59
阅读 1K+
收藏 1

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

1、我的系统运行一段时间以后,就会报错:


[ERROR] [com.xxx.app.quartz.ToExamine] - org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: loopWaitCount 0, wait millis 60003, active 7


增加maxActive的值也一样有问题,只是发生的时间间隔会加长而已。

是否在Quartz和Druid使用不当会造成连接池泄漏?二者如何配合使用?

2、详细错误:

[ERROR] [com.xxx.app.quartz.ToE] - org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: loopWaitCount 0, wait millis 60003, active 7
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: loopWaitCount 0, wait millis 60003, active 7
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
	at org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:116)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:333)
	at $Proxy12.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:189)
	at org.apache.ibatis.binding.MapperMethod.executeForList(MapperMethod.java:85)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:65)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:38)
	at $Proxy36.selectReceipt(Unknown Source)
	at com.xxx.app.quartz.ToE.fr(ToExamine.java:67)
	at com.xxx.app.quartz.ToE.execute(ToExamine.java:51)
	at sun.reflect.GeneratedMethodAccessor291.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
	at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:264)
	at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: com.alibaba.druid.pool.GetConnectionTimeoutException: loopWaitCount 0, wait millis 60003, active 7
	at com.alibaba.druid.pool.DruidDataSource.pollLast(DruidDataSource.java:1375)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1019)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:902)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4534)
	at com.alibaba.druid.filter.logging.LogFilter.dataSource_getConnection(LogFilter.java:827)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4530)
	at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4530)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:884)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:876)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:92)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
	... 18 more

3、Druid版本:0.2.23;Quartz:1.8.5;

加载中
0
wenshao
wenshao
sql执行慢了,连接不够用,申请连接等待超时。
james_you
james_you
druid 是建议自己捕获这个异常,然后等待,还是采取鸵鸟策略,直接忽略这个异常?
0
Sokos
Sokos

@wenshao  上次发生问题以后,完全同样的代码,把数据库连接池换成Proxool以后已经稳定运行一周,而使用Druid的话48小时内就会报这个错误。

这个是由于慢SQL造成的吗?但是日志里面SQL执行时间基本是在5MS以下的,每秒处理的SQL不会超过20条,而我的连接个数配置为160了。

是不是连接池泄漏了?

0
Sokos
Sokos
@wenshao 如果是连接池泄漏,如何定位在什么地方造成了泄漏呢?
Sokos
Sokos
@千纸鹤 没再用Druid了,已经换回原来的连接池。。。
千纸鹤
千纸鹤
你用quartz是怎么用的,我在用的时候没有出现你说的异常啊,要等48小时?
返回顶部
顶部