Skip to content

Spring Kafka not working properly with Java 21 Virtual Threads, listeners are tied to a platform thread forever #3074

@Moscagus

Description

@Moscagus

jstack.txt
jcmd.txt
Spring Boot 3.2.3

Virtual Kafka listeners are tied to a platform thread forever.

The problem I see is that validating with jcmd and jstack the listeners are tied to a platform thread forever.
Therefore it does not make effective use of virtual threads.
Without messages in Kafka and with a concurrency of 20, I have 20 platform threads carrying the virtual threads.

I have 3 cores. Therefore I have to have only 3 ForkJoinPool-1-worker platform threads waiting.
But in reality I have 3 waiting and another 20 carrying the listeners.

[oracle@vtuerto kafka-2602]$ cat jstack.txt | grep -A 1 ForkJoinPool-1-worker | grep WAITING
java.lang.Thread.State: TIMED_WAITING (parking)
java.lang.Thread.State: WAITING (parking)
java.lang.Thread.State: WAITING (parking)
[oracle@vtuerto kafka-2602]$ cat jstack.txt | grep -A 1 ForkJoinPool-1-worker | grep Carrying
Carrying virtual thread #38
Carrying virtual thread #73
Carrying virtual thread #47
Carrying virtual thread #76
Carrying virtual thread #80
Carrying virtual thread #61
Carrying virtual thread #43
Carrying virtual thread #92
Carrying virtual thread #45
Carrying virtual thread #64
Carrying virtual thread #84
Carrying virtual thread #88
Carrying virtual thread #69
Carrying virtual thread #96
Carrying virtual thread #100
Carrying virtual thread #104
Carrying virtual thread #108
Carrying virtual thread #112
Carrying virtual thread #116
Carrying virtual thread #51

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions