#147 - Polishing.
Configure a single executorService for the entire application.
This commit is contained in:
@@ -24,21 +24,22 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collector;
|
import java.util.stream.Collector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
import org.springframework.data.release.model.Project;
|
import org.springframework.data.release.model.Project;
|
||||||
import org.springframework.data.release.model.ProjectAware;
|
import org.springframework.data.release.model.ProjectAware;
|
||||||
import org.springframework.data.release.utils.ListWrapperCollector;
|
import org.springframework.data.release.utils.ListWrapperCollector;
|
||||||
@@ -47,7 +48,6 @@ import org.springframework.data.util.Streamable;
|
|||||||
import org.springframework.plugin.core.PluginRegistry;
|
import org.springframework.plugin.core.PluginRegistry;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build executor service.
|
* Build executor service.
|
||||||
@@ -58,23 +58,19 @@ import org.springframework.util.StringUtils;
|
|||||||
class BuildExecutor {
|
class BuildExecutor {
|
||||||
|
|
||||||
private final @NonNull PluginRegistry<BuildSystem, Project> buildSystems;
|
private final @NonNull PluginRegistry<BuildSystem, Project> buildSystems;
|
||||||
private final Logger logger;
|
|
||||||
private final MavenProperties mavenProperties;
|
private final MavenProperties mavenProperties;
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
|
|
||||||
public BuildExecutor(PluginRegistry<BuildSystem, Project> buildSystems, Logger logger,
|
public BuildExecutor(PluginRegistry<BuildSystem, Project> buildSystems, Logger logger,
|
||||||
MavenProperties mavenProperties) {
|
MavenProperties mavenProperties, ExecutorService buildExecutor) {
|
||||||
|
|
||||||
this.buildSystems = buildSystems;
|
this.buildSystems = buildSystems;
|
||||||
this.logger = logger;
|
|
||||||
this.mavenProperties = mavenProperties;
|
this.mavenProperties = mavenProperties;
|
||||||
|
|
||||||
if (this.mavenProperties.isParallelize()) {
|
if (this.mavenProperties.isParallelize()) {
|
||||||
int processors = Runtime.getRuntime().availableProcessors();
|
this.executor = buildExecutor;
|
||||||
int parallelity = Math.max(2, (processors / 2));
|
|
||||||
executor = new ThreadPoolExecutor(parallelity, parallelity, 10, TimeUnit.MINUTES, new ArrayBlockingQueue<>(256));
|
|
||||||
} else {
|
} else {
|
||||||
executor = ImmediateExecutorService.INSTANCE;
|
this.executor = ImmediateExecutorService.INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,8 +222,8 @@ class BuildExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%20s - %s", project.getName(),
|
return String.format("%-14s - %s", project.getName(),
|
||||||
isSuccessful() ? "Successful" : "Error: " + failure.getMessage());
|
isSuccessful() ? "🆗 Successful" : "🧨 Error: " + failure.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuccessful() {
|
public boolean isSuccessful() {
|
||||||
@@ -260,8 +256,8 @@ class BuildExecutor {
|
|||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append("Execution summary");
|
builder.append("Execution summary");
|
||||||
builder.append("\n");
|
builder.append(IOUtils.LINE_SEPARATOR);
|
||||||
builder.append(StringUtils.collectionToDelimitedString(executions, "\n"));
|
builder.append(executions.stream().map(it -> "\t" + it).collect(Collectors.joining(IOUtils.LINE_SEPARATOR)));
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.release.utils;
|
package org.springframework.data.release.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;
|
import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;
|
||||||
@@ -23,13 +25,18 @@ import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@Slf4j
|
||||||
class ExecutorConfiguration {
|
class ExecutorConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ThreadPoolExecutorFactoryBean executorService() {
|
public ThreadPoolExecutorFactoryBean executorService() {
|
||||||
|
|
||||||
|
int processors = Runtime.getRuntime().availableProcessors();
|
||||||
|
int threadCount = Math.max(2, processors - 4);
|
||||||
|
log.info(String.format("Setting up Executor Service with %d Threads", threadCount));
|
||||||
|
|
||||||
ThreadPoolExecutorFactoryBean scheduler = new ThreadPoolExecutorFactoryBean();
|
ThreadPoolExecutorFactoryBean scheduler = new ThreadPoolExecutorFactoryBean();
|
||||||
scheduler.setCorePoolSize(Runtime.getRuntime().availableProcessors());
|
scheduler.setCorePoolSize(threadCount);
|
||||||
scheduler.setQueueCapacity(32);
|
scheduler.setQueueCapacity(32);
|
||||||
|
|
||||||
return scheduler;
|
return scheduler;
|
||||||
|
|||||||
Reference in New Issue
Block a user