diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java index ae5394b285..85c82b47dd 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.time.LocalDateTime; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; @@ -32,6 +31,9 @@ public class DemoController { demoService.testTx(); } + /** + * 异步方式1,手动submit + */ @GetMapping("testthreadpool") public void testThreadPool() { System.out.println(LocalDateTime.now().getSecond());; @@ -43,7 +45,7 @@ public class DemoController { Future future3 = executorService.submit(() -> demoService.testThreadPool()); try { - + // 可以获取返回值,此处会阻塞 Boolean o1 = future1.get(); System.out.println(LocalDateTime.now().getSecond()); @@ -61,6 +63,9 @@ public class DemoController { } } + /** + * 异步方式2,service方法中加注解@Async + */ @GetMapping("testthreadpoolasyncs") public void testThreadPoolAsync() { System.out.println(LocalDateTime.now().getSecond());