79653777

Date: 2025-06-05 04:16:43
Score: 0.5
Natty:
Report link

You mentioned in your question the option spring.virtual.threads.enabled=true. Just to clarify, you mean spring.threads.virtual.enabled=true right?

Also, if you would like to return the response immediately, may I propose to change your code from:

@GetMapping
    public ResponseEntity<String> hello() {
        log.info("Received request in controller. Handled by thread: {}. Is Virtual Thread?: {}",
                Thread.currentThread().getName(), Thread.currentThread().isVirtual());
        helloService.hello();
        return ResponseEntity.ok("Hello, World!");
    }

to something like:

@GetMapping
    public ResponseEntity<String> hello() {
        log.info("Received request in controller. Handled by thread: {}. Is Virtual Thread?: {}",
                Thread.currentThread().getName(), Thread.currentThread().isVirtual());
        CompletableFuture.runAsync(() -> helloService.hello());
        return ResponseEntity.ok("Hello, World!");
    }

I tested on my local and this works.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: user30673520