Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

mp911de/spring-boot-virtual-threads-experiment

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Loom Experiment using Spring Boot, Spring WebMVC, and Postgres

This repository contains an experiment that uses a Spring Boot application with Virtual Threads.

Involved components:

This experiment evolves incrementally, find the previous state at https://github.com/mp911de/spring-boot-virtual-threads-experiment/tree/boot-2.4.

You need Java 19 (EAP) with --enable-preview to run the example.

Customization of a vanilla Spring Boot with Tomcat application:

@Bean
AsyncTaskExecutor applicationTaskExecutor() {
    // enable async servlet support
    ExecutorService executorService = Executors.newVirtualThreadPerTaskExecutor();
    return new TaskExecutorAdapter(executorService::execute);
}

@Bean
TomcatProtocolHandlerCustomizer<?> protocolHandlerVirtualThreadExecutorCustomizer() {

    return protocolHandler -> {
        protocolHandler.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
    };
}

After starting the application, run GET http://localhpst:8080/where-am-i to verify you're running on a virtual thread:

$ http :8080/where-am-i                                      
HTTP/1.1 200 
Connection: keep-alive
Content-Length: 51
Content-Type: text/plain;charset=UTF-8
Date: Wed, 27 Jul 2022 09:34:23 GMT
Keep-Alive: timeout=60

VirtualThread[#82]/runnable@ForkJoinPool-1-worker-1

License

About

Project Loom Experiment using Spring Boot, Spring WebMVC, and Postgres

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.