1. In spring boot 3.2, virtual threads are allowed if the configuration is enabled. If an exception is thrown inside the scheduled task, the periodic scheduled task will never run again.

  2. If virtual threads are not enabled, even if an exception is thrown inside the scheduled task, the periodic scheduled task will still run again

  3. Is it normal that the timing task of virtual thread and non-virtual thread throws an exception and produces completely different results

  4. code

package com.example.democonnector;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class ScheduledBean {

    @Scheduled(fixedDelayString = "1000")
    public void ticker() {
        final var roll = new Random().nextInt(0, 100);
        System.out.println("Rolled " + roll);
        if (roll > 50) {
            System.out.println("Error " + roll);
            throw new RuntimeException("I failed!");
        }
    }
}
  1. config
spring:
  threads:
    virtual:
      enabled: true
  1. Output(The scheduled task is not executed after Error is generated)
Connected to the target VM, address: '127.0.0.1:54269', transport: 'socket'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.2.0)

2023-12-18T02:37:33.836+08:00  INFO 55415 --- [           main] c.e.d.DemoConnectorApplication           : Starting DemoConnectorApplication using Java 21.0.1 with PID 55415 (/Users/zhou/IdeaProjects/open/demo-connector/target/classes started by zhou in /Users/zhou/IdeaProjects/open/demo-connector)
2023-12-18T02:37:33.847+08:00  INFO 55415 --- [           main] c.e.d.DemoConnectorApplication           : No active profile set, falling back to 1 default profile: "default"
2023-12-18T02:37:34.781+08:00  INFO 55415 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2023-12-18T02:37:34.790+08:00  INFO 55415 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-12-18T02:37:34.791+08:00  INFO 55415 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.16]
2023-12-18T02:37:34.837+08:00  INFO 55415 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-12-18T02:37:34.838+08:00  INFO 55415 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 929 ms
2023-12-18T02:37:35.265+08:00  INFO 55415 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path ''
2023-12-18T02:37:35.281+08:00  INFO 55415 --- [           main] c.e.d.DemoConnectorApplication           : Started DemoConnectorApplication in 1.932 seconds (process running for 2.745)
Rolled 50
Rolled 20
Rolled 4
Rolled 76
Error 76

Comment From: philwebb

I think this is a duplicate of https://github.com/spring-projects/spring-framework/issues/31749

Comment From: philwebb

@zxuanhong Can you please try the latest 3.2.1-SNAPSHOT to confirm this is fixed?

Comment From: zxuanhong

@philwebb Thank you very much. It has been confirmed that it has been fixed in 3.2.1. Therefore, I will directly close this issue SpringBoot When the spring configuration enables virtual threads, if an exception occurs inside the scheduled task, the scheduled task will not be executed