← Back to list

Don’t Wait for Spring Boot 3.2 — Enable Virtual Threads Manually Today

We all know Java 21 shipped production ready implementation of Virtual Threads. And how amazing they are as well, So Spring Boot also…

Sukresh Manda · 2026-06-07 13:33 · 12 claps · 2.0 min read
#spring-boot #java #tomcat #virtual-threads #short-read
Open on Medium ↗

Don’t Wait for Spring Boot 3.2 — Enable Virtual Threads Manually Today

We all know Java 21 shipped production ready implementation of Virtual Threads. And how amazing they are as well, So Spring Boot also shipped it to be enabled for per request processing sine v3.2+.

There are a lot of projects who haven’t yet migrated to Spring 3.2+, so I am writing this mini blog to try it,

How to enable in 3.2 or later?

  • Use 3.2 or later SPring Boot

  • Add a property to simply enable it.

  • You will start seeing the requests are handled via Virtual Threads

NOTE: I just logged the entire object, you can verify with isVirtual property also

How to enable for before 3.2?

Before 3.2 Spring Boot, uses Platform Threads to assign per request handling.

Before trying to use Viartual Threads, let’s take a look at what happends when a Spring Boot application starts, and it’s execution order (vague)

SpringApplication.run()
        ↓
ServletWebServerApplicationContext
        ↓
TomcatServletWebServerFactory
        ↓
TomcatWebServer
        ↓
Tomcat.start()
        ↓
Connector.start()
        ↓
ProtocolHandler.start()
        ↓
NioEndpoint.start()
        ↓
AbstractEndpoint.createExecutor()

Since TomcatServletWebServerFactory is a Bean we can customize, let’s use this to update the Thread Executor.

@Bean
WebServerFactoryCustomizer<TomcatServletWebServerFactory> virtualThreadsTomcat() {
    return factory -> factory.addConnectorCustomizers(connector -> {

        Executor executor = Executors.newVirtualThreadPerTaskExecutor();

        ProtocolHandler protocolHandler = connector.getProtocolHandler();

        if (protocolHandler instanceof AbstractProtocol<?> protocol) {

            //IMP: Updating the executor part
            protocol.setExecutor(executor);
        }
    });
}

Now we can see the Threads being used are Virtual rather than Platform.

Important Distinction:

  • It’s always better to upgrade Spring rather than doing these.
  • And updating the Protocol executor might not work everywhere else like @Async and other places where we might be using.

Thanks for reading 😊


메타데이터
post_id
0f5d9a38e2f1
slug
dont-wait-for-spring-boot-3-2-enable-virtual-threads-manually-today-0f5d9a38e2f1
url
https://medium.com/@mandasukresh/dont-wait-for-spring-boot-3-2-enable-virtual-threads-manually-today-0f5d9a38e2f1
canonical_url
https://medium.com/@mandasukresh/dont-wait-for-spring-boot-3-2-enable-virtual-threads-manually-today-0f5d9a38e2f1
author_url
https://medium.com/@mandasukresh
status
ok
fetched_at
2026-07-14 23:28:58