From 3b4fdf64ddf7478580144e5d1fca88c56a685464 Mon Sep 17 00:00:00 2001 From: lishuai <1793460677@qq.com> Date: Thu, 11 Jul 2024 09:33:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/org/nl/ApplicationTest.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/acs2/nladmin-system/nlsso-server/src/test/java/org/nl/ApplicationTest.java b/acs2/nladmin-system/nlsso-server/src/test/java/org/nl/ApplicationTest.java index 76c4d83da..a2797c38e 100644 --- a/acs2/nladmin-system/nlsso-server/src/test/java/org/nl/ApplicationTest.java +++ b/acs2/nladmin-system/nlsso-server/src/test/java/org/nl/ApplicationTest.java @@ -9,6 +9,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.scheduling.annotation.Scheduled; import java.util.Scanner; +import java.util.concurrent.*; /** * @Author: lyd @@ -32,9 +33,9 @@ public class ApplicationTest { System.out.println("请输入第一个数:"); int c = scanner.nextInt(); //求最小值 - int min = (((a < b) ? a : b) < c) ?((a < b) ? a : b):c; + int min = (((a < b) ? a : b) < c) ? ((a < b) ? a : b) : c; //求最大值 - int max = (((a > b) ? a : b) > c) ?((a > b) ? a : b):c; + int max = (((a > b) ? a : b) > c) ? ((a > b) ? a : b) : c; //求中间值 int mid = a + b + c - max - min; //排序 @@ -50,10 +51,32 @@ public class ApplicationTest { } - @org.testng.annotations.Test + @Test void demo1() { + CompletableFuture future = CompletableFuture.supplyAsync(() -> { + try { + Thread.sleep(3000); // 假设这是一个耗时的操作 + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException("Interrupted", e); + } + return "Result"; + }); - + try { + String result = future.get(2, TimeUnit.SECONDS); // 设置超时时间为2秒 + System.out.println(result); + } catch (CompletionException e) { + Throwable cause = e.getCause(); + if (cause instanceof TimeoutException) { + System.out.println("Operation timed out"); + } else { + throw e; // rethrow other exceptions + } + } catch (Exception e) { + throw new RuntimeException(e); + } } + }