Pārlūkot izejas kodu

修复threadLocal无法正常初始化的问题

FutureYu 1 gadu atpakaļ
vecāks
revīzija
8cdd67e909

+ 9 - 9
insert-app/src/main/java/db/handler/PackageHandler.java

@@ -70,11 +70,11 @@ public class PackageHandler {
     private DelayQueue<TsdbTask> tsdbTaskBuffer = new DelayQueue<>();
     private DelayQueue<DiskTask> diskTaskBuffer = new DelayQueue<>();
 
-    // public void initBuffer() {
-    //     bufferIndex.set(0L);
-    //     bufferFullTimeCalculator.set(SpentTimeCalculator.create().begin());
-    //     packageBuffer.set(new ArrayList<>(Globals.MAX_LOG_ITEM));
-    // }
+    public void initBuffer() {
+        bufferIndex.set(0L);
+        bufferFullTimeCalculator.set(SpentTimeCalculator.create().begin());
+        packageBuffer.set(new ArrayList<>(Globals.MAX_LOG_ITEM));
+    }
 
     @Data
     @AllArgsConstructor
@@ -235,10 +235,10 @@ public class PackageHandler {
             }
         }
 
-        // if (bufferIndex.get() == null) {
-        //     log.info("初始化threadLocal");
-        //     // initBuffer();
-        // }
+        if (bufferIndex.get() == null) {
+            log.info("初始化threadLocal");
+            initBuffer();
+        }
 
         addToPackageBuffer(dataResponsePackage);
     }