Skip to content

Commit

Permalink
Ensure the common thread pool has at least 2 threads. (#1641)
Browse files Browse the repository at this point in the history
* Ensure the common thread pool has at least 2 threads.

* Add comment on why we use at least two threads.

---------

Co-authored-by: Maik Marschner <[email protected]>
  • Loading branch information
ThatRedox and leMaik committed Oct 3, 2023
1 parent 5c1165e commit 3238657
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions chunky/src/java/se/llbit/chunky/main/Chunky.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public static void main(final String[] args) {
if (cmdline.mode == CommandLineOptions.Mode.NOTHING) {
exitCode = cmdline.exitCode;
} else {
commonThreads = new ForkJoinPool(PersistentSettings.getNumThreads());
// Initialize the common thread pool.
getCommonThreads();

Chunky chunky = new Chunky(cmdline.options);
chunky.headless = cmdline.mode == Mode.HEADLESS_RENDER || cmdline.mode == Mode.SNAPSHOT;
Expand Down Expand Up @@ -329,7 +330,8 @@ public void update() {
*/
public static ForkJoinPool getCommonThreads() {
if (commonThreads == null) {
commonThreads = new ForkJoinPool(PersistentSettings.getNumThreads());
// use at least two threads to prevent deadlocks in some java versions (see #1631)
commonThreads = new ForkJoinPool(Math.max(PersistentSettings.getNumThreads(), 2));
}
return commonThreads;
}
Expand Down

0 comments on commit 3238657

Please sign in to comment.