Skip to content

Commit

Permalink
give names to NEI threads (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru authored Oct 4, 2024
1 parent a41299d commit 43918f3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main/java/codechicken/nei/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -322,14 +323,24 @@ public void execute() {
}
};

public static ForkJoinPool getPool(int poolSize) {
if (poolSize < 1) poolSize = 1;
public static ForkJoinPool forkJoinPool;

return new ForkJoinPool(poolSize);
}
static {
final ForkJoinPool.ForkJoinWorkerThreadFactory factory = new ForkJoinPool.ForkJoinWorkerThreadFactory() {

private int workerId;

public static final int numProcessors = Runtime.getRuntime().availableProcessors();
public static ForkJoinPool forkJoinPool = getPool(numProcessors * 2 / 3);
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
worker.setName("NEI-worker-thread-" + workerId++);
return worker;
}
};
int poolSize = Runtime.getRuntime().availableProcessors() * 2 / 3;
if (poolSize < 1) poolSize = 1;
forkJoinPool = new ForkJoinPool(poolSize, factory, null, false);
}

public static final RestartableTask updateFilter = new RestartableTask("NEI Item Filtering") {

Expand Down

0 comments on commit 43918f3

Please sign in to comment.