Druid 异常分析 java.sql.SQLException: interrupt Druid

双鬼带单

共 2261字,需浏览 5分钟

 · 2021-05-14

java.sql.SQLException: interrupt Druid

今天看线上一直报 java.sql.SQLException: interrupt 因为第一次遇到也在网上找了一些资料,其中网上的大部分内容如下:

  1. 我也遇到了这个问题,您这边解决了吗?我这边是双数据源,我怀疑是多数据源导致的

  2. 这个错误是什么引起的,我使用ThreadPoolExecutor运行多线程,调用shutdownNow关闭线程的时候出现的

  3. 先调用了 cacel 方法,再调用查询方法导致

  4. 因为私有云网卡和阿里云的不匹配导致了 只要是请求超过1k的就会响应不了,能连接上数据库但是没有响应

  5. 我也碰到了类似的问题,在中断某一个线程后,我紧跟着需要执行的数据库操作并没有执行。报错为  Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: interrupt

异常具体内容如下:

2021-05-10 at 16:25:05.262 CST ERROR java.sql.SQLException: interrupt
    at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1201) ~[skyrim.engine.jar:?]
    at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1086) ~[skyrim.engine.jar:?]
    at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544) ~[skyrim.engine.jar:?]
    at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:670) ~[skyrim.engine.jar:?]

查看具体的错误位置代码为:

private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLException {
    ...
    try {
      lock.lockInterruptibly();
    } catch (InterruptedException e) {
      connectErrorCount.incrementAndGet();
      throw new SQLException("interrupt", e);
    }
  ...

其中 lock 为 ReentrantLock 也就是当获取连接时,如果线程被中断就会抛出 interrupt

在我们的项目代码中,为了控制响应时间使用了

List<Callable<Record>> callableList = new ArrayList<>();

...

List<Future<Record>> futures =
               executorService.invokeAll(callableList, 300, TimeUnit.MILLISECONDS);

其中当 300 毫秒内 callableList 还没有执行完成,就会到线程进行中断,导致 Druid 在 getConnectionInternal 响应线程中断,抛出异常。


浏览 207
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报