You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/11/03 07:57:21 UTC

[GitHub] [maven-resolver] cstamas commented on a diff in pull request #213: [MRESOLVER-283] Shared executor

cstamas commented on code in PR #213:
URL: https://github.com/apache/maven-resolver/pull/213#discussion_r1012585299


##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/concurrency/DefaultResolverExecutor.java:
##########
@@ -0,0 +1,115 @@
+package org.eclipse.aether.internal.impl.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 javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.aether.impl.RepositorySystemLifecycle;
+import org.eclipse.aether.spi.concurrency.ResolverExecutor;
+import org.eclipse.aether.spi.locator.Service;
+import org.eclipse.aether.spi.locator.ServiceLocator;
+import org.eclipse.aether.util.concurrency.WorkerThreadFactory;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Default implementation of {@link ResolverExecutor}.
+ *
+ * Creates a single shared {@link ExecutorService} instance that is shut along with repository system.
+ */
+@Singleton
+@Named
+public final class DefaultResolverExecutor implements ResolverExecutor, Service
+{
+    private static final String CONF_PROP_THREADS = "maven.artifact.threads";
+
+    private static final int DEFAULT_THREADS = 5;
+
+    private final ExecutorService executorService;
+
+    /**
+     * SL ctor.
+     *
+     * @deprecated For use in SL only.
+     */
+    @Deprecated
+    public DefaultResolverExecutor()
+    {
+        this.executorService = new ThreadPoolExecutor( DEFAULT_THREADS, DEFAULT_THREADS, 3L, TimeUnit.SECONDS,
+                new LinkedBlockingQueue<>(), new WorkerThreadFactory( getClass().getSimpleName() + '-' ) );
+    }
+
+    @Inject
+    public DefaultResolverExecutor( @Named( "${" + CONF_PROP_THREADS + ":-" + DEFAULT_THREADS + "}" ) final int threads,
+                                    RepositorySystemLifecycle lifecycle )
+    {
+        if ( threads < 1 )
+        {
+            throw new IllegalArgumentException( "threads must be grater than zero" );

Review Comment:
   fixed



-- 
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