Sonar fix in LogFileReader.java 33/65133/1
authorAmaresh Kumar <kamaresh@in.ibm.com>
Fri, 7 Sep 2018 05:40:25 +0000 (11:10 +0530)
committerAmaresh Kumar <kamaresh@in.ibm.com>
Fri, 7 Sep 2018 05:40:35 +0000 (11:10 +0530)
https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=AWHFaQoGEU5FCDfKtnUf&resolved=false&severities=BLOCKER&types=BUG

Issue-ID: DMAAP-721
Change-Id: I61a0a0b5f934ac74cd49020abcc2aca0f0c69df3
Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java

index 8975f16..110c63d 100644 (file)
@@ -188,6 +188,7 @@ public class LogfileLoader extends Thread {
                         try {\r
                             Thread.sleep(1000L);\r
                         } catch (InterruptedException e) {\r
+                            Thread.currentThread().interrupt();\r
                         }\r
                         idle = false;\r
                     } else {\r
@@ -332,26 +333,25 @@ public class LogfileLoader extends Thread {
         Connection conn = null;\r
         try {\r
             conn = db.getConnection();\r
-            Statement stmt = conn.createStatement();\r
-            // Build a bitset of all records in the LOG_RECORDS table\r
-            // We need to run this SELECT in stages, because otherwise we run out of memory!\r
             RLEBitSet nbs = new RLEBitSet();\r
-            final long stepsize = 6000000L;\r
-            boolean go_again = true;\r
-            for (long i = 0; go_again; i += stepsize) {\r
-                String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize);\r
-                try(ResultSet rs = stmt.executeQuery(sql)) {\r
-                    go_again = false;\r
-                    while (rs.next()) {\r
-                        long n = rs.getLong("RECORD_ID");\r
-                        nbs.set(n);\r
-                        go_again = true;\r
+            try(Statement stmt = conn.createStatement()) {\r
+                // Build a bitset of all records in the LOG_RECORDS table\r
+                // We need to run this SELECT in stages, because otherwise we run out of memory!\r
+                final long stepsize = 6000000L;\r
+                boolean go_again = true;\r
+                for (long i = 0; go_again; i += stepsize) {\r
+                    String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize);\r
+                    try (ResultSet rs = stmt.executeQuery(sql)) {\r
+                        go_again = false;\r
+                        while (rs.next()) {\r
+                            long n = rs.getLong("RECORD_ID");\r
+                            nbs.set(n);\r
+                            go_again = true;\r
+                        }\r
                     }\r
                 }\r
             }\r
-            stmt.close();\r
             seq_set = nbs;\r
-\r
             // Compare with the range for this server\r
             // Determine the next ID for this set of record IDs\r
             RLEBitSet tbs = (RLEBitSet) nbs.clone();\r