Experiments with Project Loom's features based on these JEPs:
This includes experimenting with these features directly as well as activating them in web frameworks.
You need Java 21.
Change into the project folder experiments
and build it with mvn package
to get target/loom-experiments.jar
.
To run it:
java --enable-preview -p target/loom-experiments.jar -m loom.experiments $EXPERIMENT $ARGUMENTS
Where:
$EXPERIMENT
selects one of the experiments by name$ARGUMENTS
configures the experiment
For details on these, see specific experiments below.
Walks over all folders and files in a given directory to gather their respective sizes. Can be configured to either run as a single thread or with one virtual thread for each file/folder.
- name:
DiskStats
- arguments: see
DiskStats.java
. - package:
dev.nipafx.lab.loom.disk
A client and server that exchange messages via sockets on localhost:8080. Client protocol:
- sends a single line, terminated by a newline
- waits for a single line (i.e. a string terminated by a newline) to be received
Server protocol:
- reads a single line (i.e. a string terminated by a newline) from that socket
- waits a predetermined amount of time
- replies with the same string, including the newline
To try this out, run the client and the server in different shells.
- server
- name:
EchoServer
- arguments: see
Echo.java
.
- name:
- client
- name:
EchoClient
- arguments: see
Send.java
.,
- name:
- package:
dev.nipafx.lab.loom.echo
Note: For a much more thorough experiment with an echo server, check out Elliot Barlas' project-loom-experiment.
Starting from a given seed URL, crawls GitHub pages and prints their connections and statistics. Only runs with virtual threads but also uses/demonstrates some data-oriented programming concepts.
- name:
GitHubCrawl
- arguments: see
GitHubCrawl.java
. - package:
dev.nipafx.lab.loom.crawl
Change into the project folder frameworks/spring_boot
and build with mvn package
, then run it with:
java -jar target/loom-spring-boot.jar
Once launched, visit http://localhost:8080/api/current-thread.
To switch to virtual threads, append the command line parameter --spring.threads.virtual.enabled=true
, which sets the Spring property spring.threads.virtual.enabled
, which in turn leads to Spring using a virtual thread for each request.
As far as I know, the release notes for version 3.2 are the most up-to-date documentation on Spring and virtual threads.
Change into the project folder frameworks/quarkus
and build with mvn package
, then run it with:
java --add-opens java.base/java.lang=ALL-UNNAMED -jar target/quarkus-app/quarkus-run.jar
Once launched, visit http://localhost:8080/api/current-thread.
To switch to virtual threads, edit QuarkusEndpoints
and uncomment @RunOnVirtualThread
, which allows configuring virtual threads for individual endpoints.
This annotation requires the --add-opens
.
The artifact quarkus-netty-loom-adaptor (see pom.xml
) seems to improve performance of Quarkus on virtual threads.
As far as I know, the blog post Writing simpler reactive REST services with Quarkus Virtual Thread support is the most up-to-date documentation on Quarkus and virtual threads.