Skip to content

Commit

Permalink
feat: Add LoadMetrics support for virtual thread executor.
Browse files Browse the repository at this point in the history
  • Loading branch information
He-Pin committed Jan 19, 2025
1 parent 373c07a commit d088285
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ private[dispatch] object VirtualThreadSupport {
}
}

/**
* Try to get the default scheduler of virtual thread.
*/
def getVirtualThreadDefaultScheduler: ForkJoinPool =
try {
require(isSupported, "Virtual thread is not supported.")
val clazz = Class.forName("java.lang.VirtualThread")
val fieldName = "DEFAULT_SCHEDULER"
val field = clazz.getDeclaredField(fieldName)
field.setAccessible(true)
field.get(null).asInstanceOf[ForkJoinPool]
} catch {
case NonFatal(e) =>
// --add-opens java.base/java.lang=ALL-UNNAMED
throw new UnsupportedOperationException("Failed to create newThreadPerTaskExecutor.", e)
}

/**
* Try to get the default scheduler of virtual thread.
*/
Expand Down
2 changes: 2 additions & 0 deletions project/JdkOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ object JdkOptions extends AutoPlugin {

lazy val versionSpecificJavaOptions =
if (isJdk17orHigher) {
// for virtual threads
"--add-opens=java.base/java.lang=ALL-UNNAMED" ::
// for aeron
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" ::
// for LevelDB
Expand Down

0 comments on commit d088285

Please sign in to comment.