[alibaba/druid]事务未提交 连接关闭 提示connection holder is null

2025-11-11 256 views
7

版本 1.1.9 连接池最大最小设置 1 个 removeabndoned设置true removeAbandonedTimeout设置10s 开启事务后不提交

DefaultTransactionDefinition definition = TransationUtil.getTransationDefinition();
TransactionStatus transactionStatus = txManager.getTransaction(definition);
String complainNo = "20210123421321";
String modelComplainNo = "20210123421321";
dao.synchronizeComplainBase(complainNo, modelComplainNo);
{
    Thread.sleep(60000);
} (InterruptedException e) {
    e.printStackTrace();
}
dao.synchronizeComplainInfo(complainNo, modelComplainNo);
dao.synchronizeComplainantInfo(complainNo, modelComplainNo);
dao.synchronizeComplainTarget(complainNo, modelComplainNo);

后续再次获取连接任意数据库操作都会提示: `Caused by: java.sql.SQLException: connection holder is null

at com.alibaba.druid.pool.DruidPooledConnection.checkStateInternal(DruidPooledConnection.java:1157)

at com.alibaba.druid.pool.DruidPooledConnection.checkState(DruidPooledConnection.java:1148)

at com.alibaba.druid.pool.DruidPooledConnection.getAutoCommit(DruidPooledConnection.java:736)

at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)

at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)

at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337)

at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)

at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)

at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)

at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)

at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)

... 17 more`

回答

1

时间过长,连接被回收了

6

时间过长,连接被回收了 可是连接被回收之后,为何其他线程获取到该连接是不可用的;连接回收了应该保证其是正常连接