错误现象
最近上线了新的程序代码,程序如果执行出错,会更新状态为失败,但是上线后发现程序报错,状态一直为PROCESSING中,未成功更新状态,出错的截图如下,我们使用的是Druid连接池
先说结论:查看你调用的方法或者上游方法中有没有出现Thread.currentThread().interrupt()
方法,去掉该方法,程序即可恢复正常。
该报错出现的原因:
//Could not get Jdbc Connection错误出处
private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLException {
try {
//如果我们的方法中线程中断后,会捕获,抛出上述日志打印中的java.sql.SQLException: interrupt错误
lock.lockInterruptibly();
} catch (InterruptedException e) {
connectErrorCountUpdater.incrementAndGet(this);
throw new SQLException("interrupt", e);
}
}
public final void acquireInterruptibly(int arg)
throws InterruptedException {
// 判断线程的中断标志位是否为true,如果是则抛出中断异常
if (Thread.interrupted())
throw new InterruptedException();
if (!tryAcquire(arg))
doAcquireInterruptibly(arg);
}
我在调用公司提供的jar中某方法时,该方法使用了 Thread.currentThread().interrupt()
方法,导致线程中断,被DruidPooledConnection捕获,进而抛出了日志中的java.sql.SQLException: interrupt
,这个错并非是数据库连接/SQL语句有问题。