diff --git a/src/org/rascalmpl/dap/DebugSocketServer.java b/src/org/rascalmpl/dap/DebugSocketServer.java index ea5ef5f486..1b6adae964 100644 --- a/src/org/rascalmpl/dap/DebugSocketServer.java +++ b/src/org/rascalmpl/dap/DebugSocketServer.java @@ -26,11 +26,11 @@ */ package org.rascalmpl.dap; +import engineering.swat.watch.DaemonThreadPool; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import org.checkerframework.checker.nullness.qual.Nullable; import org.eclipse.lsp4j.debug.TerminatedEventArguments; @@ -67,7 +67,7 @@ private void startListening(Evaluator evaluator){ Socket newClient = serverSocket.accept(); if(clientSocket == null || clientSocket.isClosed()){ clientSocket = newClient; - threadPool = Executors.newCachedThreadPool(); + threadPool = DaemonThreadPool.buildConstrainedCached("rascal-debug", Math.max(2, Math.min(6, Runtime.getRuntime().availableProcessors() - 2))); debugClient = RascalDebugAdapterLauncher.start(evaluator, clientSocket, this, services, threadPool); } else { newClient.close(); diff --git a/src/org/rascalmpl/ideservices/RemoteIDEServices.java b/src/org/rascalmpl/ideservices/RemoteIDEServices.java index 0ff5cf5176..cbfc44eaca 100644 --- a/src/org/rascalmpl/ideservices/RemoteIDEServices.java +++ b/src/org/rascalmpl/ideservices/RemoteIDEServices.java @@ -26,13 +26,13 @@ */ package org.rascalmpl.ideservices; +import engineering.swat.watch.DaemonThreadPool; import java.io.PrintWriter; import java.net.InetAddress; import java.net.Socket; import java.net.URI; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; - import org.eclipse.lsp4j.jsonrpc.Launcher; import org.jline.terminal.Terminal; import org.rascalmpl.debug.IRascalMonitor; @@ -65,6 +65,7 @@ public RemoteIDEServices(int ideServicesPort, PrintWriter stderr, IRascalMonitor .setInput(socket.getInputStream()) .setOutput(socket.getOutputStream()) .configureGson(GsonUtils::configureGson) + .setExecutorService(DaemonThreadPool.buildConstrainedCached("rascal-ide-services", Math.max(2, Math.min(6, Runtime.getRuntime().availableProcessors() - 2)))) .create(); clientLauncher.startListening(); diff --git a/src/org/rascalmpl/shell/RascalCompile.java b/src/org/rascalmpl/shell/RascalCompile.java index 46afabe710..90b1ca4f95 100644 --- a/src/org/rascalmpl/shell/RascalCompile.java +++ b/src/org/rascalmpl/shell/RascalCompile.java @@ -1,17 +1,16 @@ package org.rascalmpl.shell; +import engineering.swat.watch.DaemonThreadPool; import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; import java.nio.file.Files; -import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.function.Consumer; import java.util.function.Function; @@ -120,7 +119,7 @@ private static int parallelMain(Map parsedArgs, IList preChecks, // a cachedThreadPool lazily spins-up threads, but eagerly cleans them up // this might help with left-over threads to get more memory and finish sooner. - final ExecutorService exec = Executors.newCachedThreadPool(); + final ExecutorService exec = DaemonThreadPool.buildConstrainedCached("rascal-compile", parAmount); // the for loop eagerly spawns `parAmount` workers, one for each chunk List> workers = new ArrayList<>(parAmount);