Skip to content

Commit

Permalink
Backport J21 virtual thread usage to J17 compatible version
Browse files Browse the repository at this point in the history
  • Loading branch information
Prospector committed Jun 18, 2024
1 parent 893764a commit dab771c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class UpdateCheckerThreadFactory implements ThreadFactory {
@Override
public Thread newThread(@NotNull Runnable r) {
var index = COUNT.incrementAndGet();
return Thread.ofVirtual().name("ModMenu/Update Checker/%s".formatted(index)).unstarted(r);
Thread thread = new Thread(r);
thread.setName("ModMenu/Update Checker/" + index);
return thread;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static void checkForUpdates() {
}

private static void checkForUpdates0() {
try (var executor = Executors.newThreadPerTaskExecutor(new UpdateCheckerThreadFactory())) {
var executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new UpdateCheckerThreadFactory());
try {
List<Mod> withoutUpdateChecker = new ArrayList<>();

List<Mod> updatableMods = ModMenu.MODS.values()
Expand Down Expand Up @@ -130,6 +131,8 @@ private static void checkForUpdates0() {
data.versionNumber);
}
}
} finally {
executor.shutdown();
}
}

Expand Down

0 comments on commit dab771c

Please sign in to comment.