Kafka Producer Network Thread Blocked on ArrayDeque Lock and Virtual Threads stall on ProducerBatch class Initialization in Java 21 Loom #4036
-
Hi, I’m running into what appears to be a thread contention or lock inversion issue when using virtual threads with the Kafka producer client. I’m seeing this thread blocked:
At the same time, I have many virtual threads like this:
I try to send Kafka messages via virtual threads, and during the first Kafka message send, class loading happens lazily. It seems like the virtual thread trying to send a message touches ProducerBatch and gets blocked on JVM class initialization, while possibly holding the ArrayDeque lock. Meanwhile, the Kafka sender thread is blocked waiting for that same Deque, resulting in a stall. And all my virtual threads that try to send a kafka message seems to wait on the class initialization monitor on I use Spring Kafka 3.3.6, with JDK 21, spring version 6.2.7. Is this a known issue when using Loom-based virtual threads with the Kafka producer? Should ProducerBatch be eagerly initialized on startup in a warm-up phase to avoid this situation? Any guidance helps here |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Unfortunately, this is a known limitation of Kafka Client implementation. closed as duplicated. |
Beta Was this translation helpful? Give feedback.
Unfortunately, this is a known limitation of Kafka Client implementation.
Please, consider to raise this concern (or join existing discussion ) with Apache Kafka itself. There is nothing we can do from Spring perspective.
See more info here : #3074.
closed as duplicated.
Please , consider to use search first before creating a new issue.