Skip to content

mp911de/loom-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Loom Playground Repository

This repository contains a few selected samples to illustrate behavioral differences between Java Platform Threads and Virtual Threads.

You need at least Java 19 to run these samples and you need Postgres if you want to run the Postgres-based samples.

Examples

This repository contains three types of samples:

  1. Behavioral examples:

    These illustrate differences in concurrency behavior using synchronized vs Locks. See loomdemo.standalone packages for the individual runnable classes.

  2. Spring Boot examples

    The Spring Boot examples reside in loomdemo.springboot and its subpackages. The examples demonstrate how to configure Tomcat and Spring’s AsyncTaskExecutor to use Virtual threads.

  3. JMH Benchmarks

    Benchmarks measure Virtual vs. Platform thread performance, specifically the throughput of creating and running a Runnable on a Virtual vs. Platform thread. See VirtualThreadsBenchmark.runAndAwait and ThreadPoolExecutorBenchmark.runAndAwait` benchmark. The difference in the score is an approximation for the Virtual threads overhead in comparison to pooled Platform threads.

    Benchmarks are located in the test sources and use Microbenchmark Runner to run benchmarks through Surefire/the JUnit 5 engine.

Container setup

You can use docker compose to run the database if you like:

$ docker-compose up
...
postgres_1  | 2022-09-27 11:54:59.006 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2022-09-27 11:54:59.042 UTC [59] LOG:  database system was shut down at 2022-09-27 11:54:58 UTC
postgres_1  | 2022-09-27 11:54:59.060 UTC [1] LOG:  database system is ready to accept connections

There are devcontainers configuration files provided so you can also use those to install the JDK. Install the Remote Containers extension in VSCode, open the command palette and execute >Remote-Containers: Reopen in container, or open the project in Codespaces.

Building from Source

If you want to try build this project, then use the bundled the maven wrapper. You also need JDK 19 or above.

 $ ./mvnw clean install

If you want to build with the regular mvn command, you will need Maven v3.5.0 or above.

History

For an earlier iteration on Spring Boot and Virtual Threads see the https://github.com/mp911de/spring-boot-virtual-threads-experiment repository that contains a Spring Boot example only.

License

This project is Open Source software released under the Apache 2.0 license.