1 jdk版本21.x springboot版本3.2.x
![](https://img.haomeiwen.com/i7848013/d20db9e76f2c892a.png)
2 配置文件
![](https://img.haomeiwen.com/i7848013/9c18dcd66fff7d48.png)
spring:
threads.virtual.enabled: true
3 在controller中查看tomcat线程日志
![](https://img.haomeiwen.com/i7848013/484d322e208c0f29.png)
log.info("查看controller中的请求:" + Thread.currentThread());
如果看到 VirtualThread[#238,tomcat-handler-5]/runnable@ForkJoinPool-1-worker-29
以VirtualThread开头的日志信息说明虚拟线程开启成功
4 性能
据说改用虚拟线程后,HTTP请求降低30%的耗时,并发数也有很大提升级,当于免费升级了性能
网友评论