You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.2.0 Native构建无法启用Virtual Threads问题咨询

问题:Spring Boot 3.2.0无法同时启用Native编译与Virtual Threads

我在开发一个简单Web应用,希望同时利用Native编译和Virtual Threads特性。使用Spring Boot 3.2.0时,单独构建Native可执行文件或启用Virtual Threads都能正常工作,但无法同时实现两者。

环境信息

uname -a
Linux kl-ubuntu 6.2.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct  6 10:23:26 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

java -version
java version "21" 2023-09-19
Java(TM) SE Runtime Environment Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)

示例项目POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>gvm_virtual_threads</artifactId>
    <version>0.0.1</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

唯一的Java类

package com.example.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {
    private final static Logger logger = LoggerFactory.getLogger(DemoApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/greeting")
    public String greet() {
        logger.info("Inside greeting");
        return "Hi!";
    }
}

编译命令

mvn clean -Pnative native:compile

现象与疑问

  • JVM模式下:
    • 不启用Virtual Threads时,访问接口的日志线程名为nio-8080-exec-3;
    • 启用Virtual Threads后,线程名变为omcat-handler-0,且压测后Micrometer指标jvm_threads_peak_threads会下降。
  • Native编译后:
    • 无论是否启用Virtual Threads,日志线程名都为nio-8080-exec-3;
    • 压测后jvm_threads_peak_threads指标无变化。

请问这是Spring Boot/GraalVM不支持的场景,还是我操作有误?


内容的提问来源于stack exchange,提问作者Fradantim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 12:06:24