This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch sonarbug in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 1ad24e286d68d5f0944fca5c2ae14809052be83d Author: HTHou <[email protected]> AuthorDate: Tue Jun 29 10:56:11 2021 +0800 Fix some bugs reported by sonar --- .../apache/iotdb/db/cq/ContinuousQueryService.java | 1 + .../iotdb/db/metrics/server/ServerArgument.java | 20 ++++++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/org/apache/iotdb/db/cq/ContinuousQueryService.java b/server/src/main/java/org/apache/iotdb/db/cq/ContinuousQueryService.java index 22e90ca..eb2f908 100644 --- a/server/src/main/java/org/apache/iotdb/db/cq/ContinuousQueryService.java +++ b/server/src/main/java/org/apache/iotdb/db/cq/ContinuousQueryService.java @@ -114,6 +114,7 @@ public class ContinuousQueryService implements IService { } catch (InterruptedException e) { logger.warn("Check thread still doesn't exit after 60s"); checkThread.shutdownNow(); + Thread.currentThread().interrupt(); } } } diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java b/server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java index a7e2fa7..077d93a 100644 --- a/server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java +++ b/server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java @@ -181,11 +181,7 @@ public class ServerArgument { private int getCpuRateForLinux() { try { long[] c0 = readLinuxCpu(); - try { - Thread.sleep(CPUTIME); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + Thread.sleep(CPUTIME); long[] c1 = readLinuxCpu(); if (c0 != null && c1 != null) { long idleCpuTime = c1[0] - c0[0]; @@ -197,10 +193,12 @@ public class ServerArgument { } else { return 0; } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } catch (Exception e) { logger.error("Get CPU Ratio failed", e); - return 0; } + return 0; } /** cpu ratio for windows */ @@ -211,11 +209,7 @@ public class ServerArgument { + "\\system32\\wbem\\wmic.exe process get Caption,CommandLine," + "KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount"; long[] c0 = readWinCpu(Runtime.getRuntime().exec(procCmd)); - try { - Thread.sleep(CPUTIME); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + Thread.sleep(CPUTIME); long[] c1 = readWinCpu(Runtime.getRuntime().exec(procCmd)); if (c0 != null && c1 != null) { long idletime = c1[0] - c0[0]; @@ -227,10 +221,12 @@ public class ServerArgument { } else { return 0; } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } catch (Exception e) { logger.error("Get CPU Ratio failed", e); - return 0; } + return 0; } /** read cpu info(windows) */
