未验证 提交 892c1584 编写于 作者: H Haoran Meng 提交者: GitHub

Close connection after heart beat detection complete #control-panel-cluster (#5843)

* close connection after heart beat detection complete

* remove unused imports
上级 6cb06a16
......@@ -22,6 +22,7 @@ import org.apache.shardingsphere.cluster.configuration.config.HeartbeatConfigura
import org.apache.shardingsphere.cluster.heartbeat.response.HeartbeatResult;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
......@@ -53,10 +54,11 @@ public final class HeartbeatDetect extends AbstractHeartbeatDetect {
@Override
protected Boolean detect() {
try {
PreparedStatement preparedStatement = dataSource.getConnection().prepareStatement(sql);
ResultSet result = preparedStatement.executeQuery();
return Objects.nonNull(result) && result.next();
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
try (ResultSet result = preparedStatement.executeQuery()) {
return Objects.nonNull(result) && result.next();
}
} catch (SQLException ex) {
log.error("Heart beat detect error", ex);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册