Skip to content

Commit

Permalink
Be a little more explicit with the fork join poool
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind committed Jan 29, 2024
1 parent ea81f4c commit e16865b
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.jar.Attributes;
Expand Down Expand Up @@ -851,12 +848,16 @@ private void maybeCreateClass(
0, requests.length);
} else {
int numTasks = (requests.length + requestsPerTask - 1) / requestsPerTask;
IntStream.range(0, numTasks).parallel().forEach(jobId -> {
ForkJoinTask<?>[] tasks = new ForkJoinTask[numTasks];
for (int jobId = 0; jobId < numTasks; ++jobId) {
final int startInclusive = jobId * requestsPerTask;
final int endExclusive = Math.min(requests.length, (jobId + 1) * requestsPerTask);
maybeCreateClassHelper(compiler, fileManager, requests, rootPathAsString, tempDirAsString,
startInclusive, endExclusive);
});
tasks[jobId] = ForkJoinPool.commonPool().submit(() -> {
maybeCreateClassHelper(compiler, fileManager, requests, rootPathAsString, tempDirAsString,
startInclusive, endExclusive);
});
}
Arrays.stream(tasks).forEach(ForkJoinTask::join);
}
log.error().append("Compiled in ").append(Double.toString((System.nanoTime() - startTm) / 1e9)).append("s.").endl();
} catch (final Throwable t) {
Expand Down

0 comments on commit e16865b

Please sign in to comment.