mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-04 13:17:50 +08:00
Fix SonarCloud bug “Resources should be closed” (#1667)
#1666 Fix SonarCloud bug “Resources should be closed”
This commit is contained in:
parent
1baeefc871
commit
4b027fbf02
@ -55,41 +55,41 @@ public class ZooKeeperState {
|
||||
public void getZookeeperInfo() {
|
||||
String content = cmd("srvr");
|
||||
if (StringUtils.isNotBlank(content)) {
|
||||
Scanner scannerForStat = new Scanner(content);
|
||||
while (scannerForStat.hasNext()) {
|
||||
String line = scannerForStat.nextLine();
|
||||
if (line.startsWith("Latency min/avg/max:")) {
|
||||
String[] latencys = getStringValueFromLine(line).split("/");
|
||||
minLatency = Integer.parseInt(latencys[0]);
|
||||
avgLatency = Integer.parseInt(latencys[1]);
|
||||
maxLatency = Integer.parseInt(latencys[2]);
|
||||
} else if (line.startsWith("Received:")) {
|
||||
received = Long.parseLong(getStringValueFromLine(line));
|
||||
} else if (line.startsWith("Sent:")) {
|
||||
sent = Long.parseLong(getStringValueFromLine(line));
|
||||
} else if (line.startsWith("Outstanding:")) {
|
||||
outStanding = Integer.parseInt(getStringValueFromLine(line));
|
||||
} else if (line.startsWith("Zxid:")) {
|
||||
zxid = Long.parseLong(getStringValueFromLine(line).substring(2), 16);
|
||||
} else if (line.startsWith("Mode:")) {
|
||||
mode = getStringValueFromLine(line);
|
||||
} else if (line.startsWith("Node count:")) {
|
||||
nodeCount = Integer.parseInt(getStringValueFromLine(line));
|
||||
try (Scanner scannerForStat = new Scanner(content)) {
|
||||
while (scannerForStat.hasNext()) {
|
||||
String line = scannerForStat.nextLine();
|
||||
if (line.startsWith("Latency min/avg/max:")) {
|
||||
String[] latencys = getStringValueFromLine(line).split("/");
|
||||
minLatency = Integer.parseInt(latencys[0]);
|
||||
avgLatency = Integer.parseInt(latencys[1]);
|
||||
maxLatency = Integer.parseInt(latencys[2]);
|
||||
} else if (line.startsWith("Received:")) {
|
||||
received = Long.parseLong(getStringValueFromLine(line));
|
||||
} else if (line.startsWith("Sent:")) {
|
||||
sent = Long.parseLong(getStringValueFromLine(line));
|
||||
} else if (line.startsWith("Outstanding:")) {
|
||||
outStanding = Integer.parseInt(getStringValueFromLine(line));
|
||||
} else if (line.startsWith("Zxid:")) {
|
||||
zxid = Long.parseLong(getStringValueFromLine(line).substring(2), 16);
|
||||
} else if (line.startsWith("Mode:")) {
|
||||
mode = getStringValueFromLine(line);
|
||||
} else if (line.startsWith("Node count:")) {
|
||||
nodeCount = Integer.parseInt(getStringValueFromLine(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
scannerForStat.close();
|
||||
}
|
||||
}
|
||||
|
||||
String wchsText = cmd("wchs");
|
||||
if (StringUtils.isNotBlank(wchsText)) {
|
||||
Scanner scannerForWchs = new Scanner(wchsText);
|
||||
while (scannerForWchs.hasNext()) {
|
||||
String line = scannerForWchs.nextLine();
|
||||
if (line.startsWith("Total watches:")) {
|
||||
watches = Integer.parseInt(getStringValueFromLine(line));
|
||||
try (Scanner scannerForWchs = new Scanner(wchsText)) {
|
||||
while (scannerForWchs.hasNext()) {
|
||||
String line = scannerForWchs.nextLine();
|
||||
if (line.startsWith("Total watches:")) {
|
||||
watches = Integer.parseInt(getStringValueFromLine(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
scannerForWchs.close();
|
||||
}
|
||||
}
|
||||
|
||||
String consText = cmd("cons");
|
||||
|
Loading…
Reference in New Issue
Block a user