Closed
Description
sharding-jdbc-core version-1.5.4.1
AbstractStatementAdapter方法实现中逐个close RoutedStatements集合前,先对集合做了clear操作,会导致RoutedStatements集合中的各个Statement的close方法执行不到。
目前的代码
@Override
public final void close() throws SQLException {
closed = true;
getRoutedStatements().clear();
Collection<SQLException> exceptions = new LinkedList<>();
for (Statement each : getRoutedStatements()) {
try {
each.close();
} catch (final SQLException ex) {
exceptions.add(ex);
}
}
throwSQLExceptionIfNecessary(exceptions);
}
可以修改为:
public final void close() throws SQLException {
closed = true;
Collection<SQLException> exceptions = new LinkedList<>();
for (Statement each : getRoutedStatements()) {
try {
each.close();
} catch (final SQLException ex) {
exceptions.add(ex);
}
}
getRoutedStatements().clear();
throwSQLExceptionIfNecessary(exceptions);
}