From dc7a8dc5ec384b109f6e716edcda793fafce10c5 Mon Sep 17 00:00:00 2001 From: He-Pin Date: Tue, 21 Jan 2025 03:03:57 +0800 Subject: [PATCH] chore: Add doc about virtual thread executor. --- docs/src/main/paradox/typed/dispatchers.md | 9 +++++++++ .../test/scala/docs/dispatcher/DispatcherDocSpec.scala | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/src/main/paradox/typed/dispatchers.md b/docs/src/main/paradox/typed/dispatchers.md index b3546a4416..d65312e136 100644 --- a/docs/src/main/paradox/typed/dispatchers.md +++ b/docs/src/main/paradox/typed/dispatchers.md @@ -361,6 +361,15 @@ it in `application.conf` and instantiate through an ## More dispatcher configuration examples +### Virtual Threads + +Configuring a dispatcher with virtual threads, requires Java 21 or above: + +@@snip [DispatcherDocSpec.scala](/docs/src/test/scala/docs/dispatcher/DispatcherDocSpec.scala) { #virtual-thread-dispatcher-config } + +With this, an actor will run in a virtual thread, so you may want to configure it further with : +`jdk.virtualThreadScheduler.parallelism` ,`jdk.virtualThreadScheduler.maxPoolSize` and `jdk.unparker.maxPoolSize`. + ### Fixed pool size Configuring a dispatcher with fixed thread pool size, e.g. for actors that perform blocking IO: diff --git a/docs/src/test/scala/docs/dispatcher/DispatcherDocSpec.scala b/docs/src/test/scala/docs/dispatcher/DispatcherDocSpec.scala index 137782bc2c..e9532ddabd 100644 --- a/docs/src/test/scala/docs/dispatcher/DispatcherDocSpec.scala +++ b/docs/src/test/scala/docs/dispatcher/DispatcherDocSpec.scala @@ -132,7 +132,13 @@ object DispatcherDocSpec { # Set to 1 for as fair as possible. throughput = 100 } - //#affinity-pool-dispatcher-config + //#affinity-pool-dispatcher-config + + //#virtual-thread-dispatcher-config + virtual-thread-dispatcher { + executor = virtual-thread-executor + } + //#virtual-thread-dispatcher-config //#fixed-pool-size-dispatcher-config blocking-io-dispatcher {