Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a global bounded threadpool when using persistent workers #6508

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -113,8 +114,9 @@ private static void runPersistentWorker(PackageParser parser) throws IOException
}

public static void main(String[] args) throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
PackageParserOptions options = parseArgs(args);
PackageParser parser = new PackageParser(PackageParserIoProvider.INSTANCE);
PackageParser parser = new PackageParser(PackageParserIoProvider.INSTANCE, executorService);

try {
if (isWorkerMode(args)) {
Expand Down Expand Up @@ -150,9 +152,12 @@ private static String[] parseParamFileIfUsed(String[] args) {

private final PackageParserIoProvider ioProvider;

private final ExecutorService executorService;

@VisibleForTesting
PackageParser(PackageParserIoProvider ioProvider) {
PackageParser(PackageParserIoProvider ioProvider, ExecutorService executorService) {
this.ioProvider = ioProvider;
this.executorService = executorService;
}

@VisibleForTesting
Expand Down Expand Up @@ -180,8 +185,7 @@ Map<ArtifactLocation, String> parsePackageStrings(List<ArtifactLocation> sources
throws Exception {

ListeningExecutorService executorService =
MoreExecutors.listeningDecorator(
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
MoreExecutors.listeningDecorator(this.executorService);

Map<ArtifactLocation, ListenableFuture<String>> futures = Maps.newHashMap();
for (final ArtifactLocation source : sources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -107,13 +109,15 @@ public void writeProto(MessageLite message, Path file) throws IOException {
.setIsSource(false)
.build();

private ExecutorService executorService;
private MockPackageParserIoProvider mockIoProvider;
private PackageParser parser;

@Before
public void setUp() {
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
mockIoProvider = new MockPackageParserIoProvider();
parser = new PackageParser(mockIoProvider);
parser = new PackageParser(mockIoProvider, executorService);
}

private Map<ArtifactLocation, String> parsePackageStrings() throws Exception {
Expand Down
Loading