今天看线上一直报 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 响应线程中断,抛出异常。