8324673: javacserver failed during build: RejectedExecutionException

Reviewed-by: cstein, erikj
This commit is contained in:
Daniel Jeliński 2024-04-09 14:10:58 +00:00
parent 5fb5e6c8f0
commit 3b6629cec7
2 changed files with 9 additions and 18 deletions
make/langtools/tools/javacserver/server

@ -43,14 +43,8 @@ public class CompilerThreadPool {
this.pool = Executors.newFixedThreadPool(POOLSIZE); this.pool = Executors.newFixedThreadPool(POOLSIZE);
} }
public int dispatchCompilation(String[] args) { public void execute(Runnable runnable) {
Log log = Log.get(); this.pool.execute(runnable);
try {
return pool.submit(() -> Server.runCompiler(log, args)).get();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error during compile", e);
}
} }
public void shutdown() { public void shutdown() {

@ -168,10 +168,8 @@ public class Server {
do { do {
try { try {
Socket socket = serverSocket.accept(); Socket socket = serverSocket.accept();
// Handle each incoming request in a separate thread. This is just for socket communication, // Handle each incoming request in a threapool thread
// the actual compilation will be done by the threadpool. compilerThreadPool.execute(() -> handleRequest(socket));
Thread requestHandler = new Thread(() -> handleRequest(socket));
requestHandler.start();
} catch (SocketException se) { } catch (SocketException se) {
// Caused by serverSocket.close() and indicates shutdown // Caused by serverSocket.close() and indicates shutdown
} }
@ -206,9 +204,9 @@ public class Server {
// If there has been any internal errors, notify client // If there has been any internal errors, notify client
checkInternalErrorLog(); checkInternalErrorLog();
// Perform compilation. This will call runCompiler() on a // Perform compilation
// thread in the thread pool int exitCode = runCompiler(args);
int exitCode = compilerThreadPool.dispatchCompilation(args);
Protocol.sendExitCode(out, exitCode); Protocol.sendExitCode(out, exitCode);
// Check for internal errors again. // Check for internal errors again.
@ -220,15 +218,14 @@ public class Server {
// Not much to be done at this point. The client side request // Not much to be done at this point. The client side request
// code will most likely throw an IOException and the // code will most likely throw an IOException and the
// compilation will fail. // compilation will fail.
ex.printStackTrace();
Log.error(ex); Log.error(ex);
} finally { } finally {
Log.setLogForCurrentThread(null); Log.setLogForCurrentThread(null);
} }
} }
public static int runCompiler(Log log, String[] args) { public static int runCompiler(String[] args) {
Log.setLogForCurrentThread(log);
// Direct logging to our byte array stream. // Direct logging to our byte array stream.
StringWriter strWriter = new StringWriter(); StringWriter strWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(strWriter); PrintWriter printWriter = new PrintWriter(strWriter);