From 9ec7271377808ffc8f65fd409efe00d00cefeb58 Mon Sep 17 00:00:00 2001 From: Scusemua Date: Tue, 14 Dec 2021 16:46:16 -0500 Subject: [PATCH] Added change to make Java executor support concurrency. --- .../openwhisk/runtime/java/action/Proxy.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java b/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java index 4c0dc21f..ad858ec7 100644 --- a/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java +++ b/core/java8/proxy/src/main/java/org/apache/openwhisk/runtime/java/action/Proxy.java @@ -30,6 +30,9 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -48,7 +51,20 @@ public Proxy(int port) throws IOException { this.server.createContext("/init", new InitHandler()); this.server.createContext("/run", new RunHandler()); - this.server.setExecutor(null); // creates a default executor + + if (Boolean.parseBoolean(System.getenv("__OW_ALLOW_CONCURRENT"))) { + ThreadPoolExecutor executor = new ThreadPoolExecutor( + 10, // Core size. + 25, // Max size. + 10 * 60, // Idle timeout. + TimeUnit.SECONDS, + new ArrayBlockingQueue(30) + ); + executor.allowCoreThreadTimeOut(true); + this.server.setExecutor(executor); + } else { + this.server.setExecutor(null); // Default executor. + } } public void start() {