From 3b6629cec7a2ecec8dcb5b94d8ed3e169483aa97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jeli=C5=84ski?= <djelinski@openjdk.org> Date: Tue, 9 Apr 2024 14:10:58 +0000 Subject: [PATCH] 8324673: javacserver failed during build: RejectedExecutionException Reviewed-by: cstein, erikj --- .../javacserver/server/CompilerThreadPool.java | 10 ++-------- .../tools/javacserver/server/Server.java | 17 +++++++---------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/make/langtools/tools/javacserver/server/CompilerThreadPool.java b/make/langtools/tools/javacserver/server/CompilerThreadPool.java index 3f3dea52c84..0a40a27ad87 100644 --- a/make/langtools/tools/javacserver/server/CompilerThreadPool.java +++ b/make/langtools/tools/javacserver/server/CompilerThreadPool.java @@ -43,14 +43,8 @@ public class CompilerThreadPool { this.pool = Executors.newFixedThreadPool(POOLSIZE); } - public int dispatchCompilation(String[] args) { - Log log = Log.get(); - try { - return pool.submit(() -> Server.runCompiler(log, args)).get(); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Error during compile", e); - } + public void execute(Runnable runnable) { + this.pool.execute(runnable); } public void shutdown() { diff --git a/make/langtools/tools/javacserver/server/Server.java b/make/langtools/tools/javacserver/server/Server.java index b213c992667..8d8bac76ad7 100644 --- a/make/langtools/tools/javacserver/server/Server.java +++ b/make/langtools/tools/javacserver/server/Server.java @@ -168,10 +168,8 @@ public class Server { do { try { Socket socket = serverSocket.accept(); - // Handle each incoming request in a separate thread. This is just for socket communication, - // the actual compilation will be done by the threadpool. - Thread requestHandler = new Thread(() -> handleRequest(socket)); - requestHandler.start(); + // Handle each incoming request in a threapool thread + compilerThreadPool.execute(() -> handleRequest(socket)); } catch (SocketException se) { // Caused by serverSocket.close() and indicates shutdown } @@ -206,9 +204,9 @@ public class Server { // If there has been any internal errors, notify client checkInternalErrorLog(); - // Perform compilation. This will call runCompiler() on a - // thread in the thread pool - int exitCode = compilerThreadPool.dispatchCompilation(args); + // Perform compilation + int exitCode = runCompiler(args); + Protocol.sendExitCode(out, exitCode); // Check for internal errors again. @@ -220,15 +218,14 @@ public class Server { // Not much to be done at this point. The client side request // code will most likely throw an IOException and the // compilation will fail. + ex.printStackTrace(); Log.error(ex); } finally { Log.setLogForCurrentThread(null); } } - public static int runCompiler(Log log, String[] args) { - Log.setLogForCurrentThread(log); - + public static int runCompiler(String[] args) { // Direct logging to our byte array stream. StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter);