From d2da91d4564c609ff50ffccf45b12161bd202673 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Mon, 12 Dec 2022 15:42:02 -0500 Subject: [PATCH] Use standard Java thread creation in Concurrent (#1880) The AppEngine thread factory is only useful if we can't create our own (this is no longer the case) or if we need access to AppEngine APIs (this is no longer the case). The Concurrent class is only used by the DNS writer and the CreateGroupsAction. --- .../java/google/registry/util/Concurrent.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/util/src/main/java/google/registry/util/Concurrent.java b/util/src/main/java/google/registry/util/Concurrent.java index 9d2656f56..f1210811a 100644 --- a/util/src/main/java/google/registry/util/Concurrent.java +++ b/util/src/main/java/google/registry/util/Concurrent.java @@ -14,7 +14,6 @@ package google.registry.util; -import static com.google.appengine.api.ThreadManager.currentRequestThreadFactory; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.ImmutableList.toImmutableList; import static java.lang.Math.max; @@ -30,13 +29,12 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; -import java.util.concurrent.ThreadFactory; import java.util.function.Function; -/** Utilities for multithreaded operations in App Engine requests. */ +/** Utilities for multithreaded operations. */ public final class Concurrent { - /** Maximum number of threads per pool. The actual GAE per-request limit is 50. */ + /** Maximum number of threads per pool. */ private static final int MAX_THREADS = 10; /** @@ -67,16 +65,10 @@ public final class Concurrent { checkNotNull(funk); checkNotNull(items); int threadCount = max(1, min(items.size(), maxThreadCount)); - ThreadFactory threadFactory = threadCount > 1 ? currentRequestThreadFactory() : null; - if (threadFactory == null) { - // Fall back to non-concurrent transform if we only want 1 thread, or if we can't get an App - // Engine thread factory (most likely caused by hitting this code from a command-line tool). - // Default Java system threads are not compatible with code that needs to interact with App - // Engine (such as Objectify), which we often have in funk when calling - // Concurrent.transform(). For more info see: http://stackoverflow.com/questions/15976406 + if (threadCount == 1) { return items.stream().map(funk).collect(toImmutableList()); } - ExecutorService executor = newFixedThreadPool(threadCount, threadFactory); + ExecutorService executor = newFixedThreadPool(threadCount); try { List> futures = new ArrayList<>(); for (final A item : items) {