Technoboy- commented on a change in pull request #1689: Fix bug : Use
try-with-resources or close this "ResultSet" in a "finally" clause
URL:
https://github.com/apache/incubator-dolphinscheduler/pull/1689#discussion_r362782290
##########
File path:
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/PostgrePerformance.java
##########
@@ -50,26 +50,30 @@ public MonitorRecord getMonitorRecord(Connection conn) {
Statement pstmt= null;
try{
pstmt = conn.createStatement();
- ResultSet rs1 = pstmt.executeQuery("select count(*) from
pg_stat_activity;");
- while(rs1.next()){
- monitorRecord.setThreadsConnections(rs1.getInt("count"));
- break;
+
+ try (ResultSet rs1 = pstmt.executeQuery("select count(*) from
pg_stat_activity;")) {
+ while(rs1.next()){
+ monitorRecord.setThreadsConnections(rs1.getInt("count"));
+ break;
+ }
}
- ResultSet rs2 = pstmt.executeQuery("show max_connections");
- while(rs2.next()){
- monitorRecord.setMaxConnections(
rs2.getInt("max_connections"));
- break;
+ try (ResultSet rs2 = pstmt.executeQuery("show max_connections")) {
+ while(rs2.next()){
+ monitorRecord.setMaxConnections(
rs2.getInt("max_connections"));
+ break;
+ }
}
- ResultSet rs3 = pstmt.executeQuery("select count(*) from
pg_stat_activity pg where pg.state = 'active';");
- while(rs3.next()){
-
monitorRecord.setThreadsRunningConnections(rs3.getInt("count"));
- break;
+ try (ResultSet rs3 = pstmt.executeQuery("select count(*) from
pg_stat_activity pg where pg.state = 'active';")) {
+ while(rs3.next()){
Review comment:
while ---> if
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services