Skip to content

Commit

Permalink
Add virtual thread support to the resteasy reactive scoring system
Browse files Browse the repository at this point in the history
For now the value is a bit arbitrary.
We may need to revisit and improve the code analysis to improve the scoring.
  • Loading branch information
cescoffier committed Aug 29, 2023
1 parent 3dede5c commit f62da89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,23 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
if (method.isBlocking()) {
if (method.isRunOnVirtualThread()) {
handlers.add(blockingHandlerVirtualThread);
score.add(ScoreSystem.Category.Execution, ScoreSystem.Diagnostic.ExecutionVirtualThread);
} else {
handlers.add(blockingHandler);
score.add(ScoreSystem.Category.Execution, ScoreSystem.Diagnostic.ExecutionBlocking);
}
blockingHandlerIndex = Optional.of(handlers.size() - 1);
score.add(ScoreSystem.Category.Execution, ScoreSystem.Diagnostic.ExecutionBlocking);
} else {
if (method.isRunOnVirtualThread()) {
//should not happen
log.error("a method was both non blocking and @RunOnVirtualThread, it is now considered " +
log.error("a method was both non-blocking and @RunOnVirtualThread, it is now considered " +
"@RunOnVirtual and blocking");
handlers.add(blockingHandlerVirtualThread);
score.add(ScoreSystem.Category.Execution, ScoreSystem.Diagnostic.ExecutionVirtualThread);
} else {
handlers.add(NonBlockingHandler.INSTANCE);
score.add(ScoreSystem.Category.Execution, ScoreSystem.Diagnostic.ExecutionNonBlocking);
}
score.add(ScoreSystem.Category.Execution, ScoreSystem.Diagnostic.ExecutionNonBlocking);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public String toString() {
public static Diagnostic ExecutionNonBlocking = new Diagnostic("Dispatched on the IO thread", 100);
public static Diagnostic ExecutionBlocking = new Diagnostic("Relies on a blocking worker thread", 0);

public static Diagnostic ExecutionVirtualThread = new Diagnostic("Relies on a virtual thread", 66);

public static Diagnostic ResourceSingleton = new Diagnostic("Single resource instance for all requests", 100);
public static Diagnostic ResourcePerRequest = new Diagnostic("New resource instance for every request", 0);

Expand Down

0 comments on commit f62da89

Please sign in to comment.