You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "laeubi (via GitHub)" <gi...@apache.org> on 2023/02/06 12:08:33 UTC

[GitHub] [maven-resolver] laeubi commented on a diff in pull request #239: [MRESOLVER-318] Support dynamic core count for thread config

laeubi commented on code in PR #239:
URL: https://github.com/apache/maven-resolver/pull/239#discussion_r1097296487


##########
maven-resolver-util/src/main/java/org/eclipse/aether/util/concurrency/ExecutorUtils.java:
##########
@@ -0,0 +1,179 @@
+package org.eclipse.aether.util.concurrency;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.util.ConfigUtils;
+
+/**
+ * Utilities for executors and sizing them.
+ *
+ * @since 1.9.5
+ */
+public final class ExecutorUtils
+{
+    /**
+     * Shared instance of "direct executor".
+     */
+    public static final Executor DIRECT_EXECUTOR = Runnable::run;
+
+    /**
+     * Creates new thread pool {@link ExecutorService}. The {@code poolSize} parameter but be greater than 1.
+     */
+    public static ExecutorService threadPool( int poolSize, String namePrefix )
+    {
+        if ( poolSize < 2 )
+        {
+            throw new IllegalArgumentException(
+                    "Invalid poolSize: " + poolSize + ". Must be greater than 1." );
+        }
+        return new ThreadPoolExecutor( poolSize, poolSize, 3L, TimeUnit.SECONDS,

Review Comment:
   Maybe better use a work stealing pool with a concurrency level?
   `java.util.concurrent.Executors.newWorkStealingPool(int)`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org