You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/virtual-threads.adoc
+8-31Lines changed: 8 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ include::_attributes.adoc[]
17
17
:topics: virtual-threads
18
18
:extensions: io.quarkus:quarkus-core
19
19
20
-
This guide explains how to benefit from Java 19+ virtual threads in Quarkus application.
20
+
This guide explains how to benefit from Java 21+ virtual threads in Quarkus application.
21
21
22
22
== What are virtual threads?
23
23
@@ -40,7 +40,8 @@ It isn't a class distinct from link:{Thread}[Thread] or `VirtualThread` but rath
40
40
=== Differences between virtual threads and platform threads
41
41
We will give a brief overview of the topic here; please refer to the link:{vthreadjep}[JEP 425] for more information.
42
42
43
-
Virtual threads are a feature available since Java 19, aiming at providing a cheap alternative to platform threads for I/O-bound workloads.
43
+
Virtual threads are a feature available since Java 19 (Java 21 is the first LTS version including virtual threads),
44
+
aiming at providing a cheap alternative to platform threads for I/O-bound workloads.
44
45
45
46
Until now, platform threads were the concurrency unit of the JVM.
46
47
They are a wrapper over OS structures.
@@ -165,7 +166,7 @@ Quarkus handles the creation of the virtual thread and the offloading.
165
166
Since virtual threads are disposable entities, the fundamental idea of `@RunOnVirtualThread` is to offload the execution of an endpoint handler on a new virtual thread instead of running it on an event-loop or worker thread (in the case of RESTEasy Reactive).
166
167
167
168
To do so, it suffices to add the link:{runonvthread}[@RunOnVirtualThread] annotation to the endpoint.
168
-
If the Java Virtual Machine used to **run** the application provides virtual thread support (so, Java 19 or later versions), then the endpoint execution is offloaded to a virtual thread.
169
+
If the Java Virtual Machine used to **run** the application provides virtual thread support (so Java 21 or later versions), then the endpoint execution is offloaded to a virtual thread.
169
170
It will then be possible to perform blocking operations without blocking the platform thread upon which the virtual thread is mounted.
170
171
171
172
In the case of RESTEasy Reactive, this annotation can only be used on endpoints annotated with link:{blockingannotation}[@Blocking] or
@@ -192,34 +193,17 @@ Add the following dependency to your build file:
Finally, until Java 21, you need to configure your compiler plugin with the `--enable-preview` flag.
207
-
If you use Maven, make sure that the configuration of the Maven compiler plugin is the following:
208
-
209
-
[source, xml]
210
-
----
211
-
<plugin>
212
-
<artifactId>maven-compiler-plugin</artifactId>
213
-
<version>${compiler-plugin.version}</version>
214
-
<configuration>
215
-
<compilerArgs>
216
-
<arg>--enable-preview</arg>
217
-
<arg>-parameters</arg>
218
-
</compilerArgs>
219
-
</configuration>
220
-
</plugin>
221
-
----
222
-
223
207
==== Three development and execution models
224
208
225
209
The example below shows the differences between three endpoints, all of them querying a _fortune_ in the database then
@@ -382,14 +366,7 @@ mvn package
382
366
383
367
=== Using a local GraalVM installation
384
368
385
-
To compile a Quarkus applications leveraging `@RunOnVirtualThread` into native executable, you must be sure to use a GraalVM / Mandrel `native-image` supporting virtual threads, so providing at least Java 19+.
386
-
387
-
Then, until Java 21, you need to add the following property to your `application.properties` file:
To compile a Quarkus applications leveraging `@RunOnVirtualThread` into a native executable, you must be sure to use a GraalVM / Mandrel `native-image` supporting virtual threads, so providing at least Java 21.
393
370
394
371
Build the native executable as indicated on xref:./building-native-image.adoc[the native compilation guide].
0 commit comments