-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the QuarkusForkJoinWorkerThreadFactory for fork-join pools
- Loading branch information
Showing
7 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
core/deployment/src/main/java/io/quarkus/deployment/ForkJoinPoolProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.quarkus.deployment; | ||
|
||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.SystemPropertyBuildItem; | ||
|
||
public final class ForkJoinPoolProcessor { | ||
|
||
@BuildStep | ||
SystemPropertyBuildItem setProperty() { | ||
return new SystemPropertyBuildItem("java.util.concurrent.ForkJoinPool.common.threadFactory", | ||
"io.quarkus.bootstrap.forkjoin.QuarkusForkJoinWorkerThreadFactory"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...strap/runner/src/main/java/io/quarkus/bootstrap/forkjoin/QuarkusForkJoinWorkerThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.quarkus.bootstrap.forkjoin; | ||
|
||
import io.quarkus.bootstrap.runner.RunnerClassLoader; | ||
import java.util.concurrent.ForkJoinPool; | ||
import java.util.concurrent.ForkJoinWorkerThread; | ||
|
||
public class QuarkusForkJoinWorkerThread extends ForkJoinWorkerThread { | ||
|
||
private static volatile ClassLoader qClassloader; | ||
|
||
protected QuarkusForkJoinWorkerThread(ForkJoinPool pool) { | ||
super(pool); | ||
} | ||
|
||
public static synchronized void setQuarkusAppClassloader(RunnerClassLoader runnerClassLoader) { | ||
if (qClassloader != null) { | ||
throw new IllegalStateException("Attempting to set the Quarkus root classloader while it was already set"); | ||
} | ||
if (runnerClassLoader == null) { | ||
throw new IllegalStateException("Attempting to set the Quarkus root classloader to null"); | ||
} | ||
qClassloader = runnerClassLoader; | ||
} | ||
|
||
protected void onStart() { | ||
super.onStart(); | ||
if (qClassloader == null) { | ||
throw new IllegalStateException( | ||
"Fork Join pool initialization has been triggered before the primary classloader has been initialized. " + | ||
"Use this stacktrace to figure out what triggered it, and avoid using the Fork Join pool this early during the boot process."); | ||
} else { | ||
super.setContextClassLoader(qClassloader); | ||
} | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...unner/src/main/java/io/quarkus/bootstrap/forkjoin/QuarkusForkJoinWorkerThreadFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.bootstrap.forkjoin; | ||
|
||
import java.util.concurrent.ForkJoinPool; | ||
import java.util.concurrent.ForkJoinWorkerThread; | ||
|
||
public final class QuarkusForkJoinWorkerThreadFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory { | ||
|
||
public QuarkusForkJoinWorkerThreadFactory() { | ||
//Needs a public constructor for the JDK to pick it up | ||
} | ||
|
||
@Override | ||
public ForkJoinWorkerThread newThread(ForkJoinPool pool) { | ||
return new QuarkusForkJoinWorkerThread(pool); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters