Ver código fonte

日志发送 异步问题

huangxingxing 1 ano atrás
pai
commit
901d24765e

+ 9 - 4
src/main/java/com/miniframe/disaster/service/LogService.java

@@ -10,6 +10,7 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.util.concurrent.CompletableFuture;
 
 /**
  * 日志存储
@@ -61,13 +62,17 @@ public class LogService {
             bwriter.newLine();
             bwriter.close();
             writer.close();
-            System.out.println("s消息发送:aid:"+aid+"--log:"+log);
-            WebsocketEndPoint webs =  (WebsocketEndPoint) UtilTools.getBean("websocketEndPoint");
-            webs.sendMessageToUser(String.valueOf(aid),log);
-            System.out.println("d消息发送:aid:"+aid+"--log:"+log);
         } catch (IOException e) {
             e.printStackTrace();
         }
+        CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()->{
+                System.out.println("s消息发送:aid:"+aid+"--log:"+log);
+                WebsocketEndPoint webs =  (WebsocketEndPoint) UtilTools.getBean("websocketEndPoint");
+                webs.sendMessageToUser(String.valueOf(aid),log);
+                System.out.println("d消息发送:aid:"+aid+"--log:"+log);
+            return null;
+        });
+
     }
     /**
      * 文件内容追加