diff --git a/Partner-Core/src/main/java/work/slhaf/partner/core/action/runner/execution/CommandExecutionService.java b/Partner-Core/src/main/java/work/slhaf/partner/core/action/runner/execution/CommandExecutionService.java index b6439263..16b2dde6 100644 --- a/Partner-Core/src/main/java/work/slhaf/partner/core/action/runner/execution/CommandExecutionService.java +++ b/Partner-Core/src/main/java/work/slhaf/partner/core/action/runner/execution/CommandExecutionService.java @@ -10,16 +10,12 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; public class CommandExecutionService { public static final CommandExecutionService INSTANCE = new CommandExecutionService(); - private final ExecutorService readerExecutor = Executors.newVirtualThreadPerTaskExecutor(); - private CommandExecutionService() { } @@ -47,7 +43,7 @@ public class CommandExecutionService { try { Process process = startProcess(launchSpec); - Thread stdoutThread = new Thread(() -> { + Thread stdoutThread = Thread.startVirtualThread(() -> { try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { String line; while ((line = reader.readLine()) != null) { @@ -57,7 +53,7 @@ public class CommandExecutionService { } }); - Thread stderrThread = new Thread(() -> { + Thread stderrThread = Thread.startVirtualThread(() -> { try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) { String line; while ((line = reader.readLine()) != null) { @@ -67,9 +63,6 @@ public class CommandExecutionService { } }); - readerExecutor.execute(stdoutThread); - readerExecutor.execute(stderrThread); - int exitCode = process.waitFor(); stdoutThread.join(); stderrThread.join(); @@ -103,8 +96,8 @@ public class CommandExecutionService { session.setStdoutBuffer(stdoutBuffer); session.setStderrBuffer(stderrBuffer); - readerExecutor.execute(() -> readToBuffer(process.getInputStream(), stdoutBuffer)); - readerExecutor.execute(() -> readToBuffer(process.getErrorStream(), stderrBuffer)); + Thread.startVirtualThread(() -> readToBuffer(process.getInputStream(), stdoutBuffer)); + Thread.startVirtualThread(() -> readToBuffer(process.getErrorStream(), stderrBuffer)); return session; } catch (Exception e) {