https://github.com/linux-china/spring-boot-virtual-thread-demo
Spring Boot Virtual Thread demo with Tomcat
https://github.com/linux-china/spring-boot-virtual-thread-demo
Last synced: about 1 year ago
JSON representation
Spring Boot Virtual Thread demo with Tomcat
- Host: GitHub
- URL: https://github.com/linux-china/spring-boot-virtual-thread-demo
- Owner: linux-china
- Created: 2023-06-14T09:21:01.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-24T05:50:19.000Z (over 1 year ago)
- Last Synced: 2025-04-26T12:13:16.933Z (about 1 year ago)
- Language: Java
- Size: 26.4 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Spring Boot Virtual Thread Demo
==================================
Spring Boot Virtual Thread Demo with Tomcat.
* Java 21: https://jdk.java.net/21/
* Spring Boot 3.2.0 with Tomcat 10.1.16
# Tomcat Virtual Threads Configuration
Please add following configuration to `application.properties`:
```properties
spring.threads.virtual.enabled=true
```
# Reactive on Virtual Threads
```
@GetMapping("/reactive")
public Mono reactive() {
return Mono.just("Hello Reactor!").doOnNext(s -> {
System.out.println("Reactive on " + Thread.currentThread());
});
}
```
# Async method on Virtual Threads
Add `@EnableAsync` on Spring Boot main class, then add `@Async` on method.
# References
* JDK 21: https://openjdk.org/projects/jdk/21/
* JEP 444: Virtual Threads - https://openjdk.org/jeps/444
* Spring Boot Asynchronous Requests: https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-ann-async.html
* Apache Tomcat 10.1.10 available: https://lists.apache.org/thread/20lp6fcf5c0gb5p32k9vwl8xbscc1h68
* Embracing Virtual Threads: https://spring.io/blog/2022/10/11/embracing-virtual-threads
* Working with Virtual Threads in Spring 6: https://www.baeldung.com/spring-6-virtual-threads
* When virtual threads are enabled, configure Jetty to use
them: https://github.com/spring-projects/spring-boot/issues/35703