当我使用 CuratorFrameworkFactory.newClient() 时,获取 KafkaConsumer 对于多线程访问错误是不安全的 [英] Getting KafkaConsumer is not safe for multi-threaded access error when I use CuratorFrameworkFactory.newClient()

查看:28
本文介绍了当我使用 CuratorFrameworkFactory.newClient() 时,获取 KafkaConsumer 对于多线程访问错误是不安全的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面收到此错误:

java.util.ConcurrentModificationException: KafkaConsumer is not safe for multi-threaded access

当我将其包含在我的代码中时:

when I include this in my code:

CuratorFrameworkFactory.newClient()

我不明白是什么导致了错误.有什么帮助吗?

I don't understand what's causing the error. Any help?

谢谢.

推荐答案

Kafka Javdocs 明确提到:

Kafka Javdocs clearly mentions that :

Kafka 消费者不是线程安全的.所有网络 I/O 都发生在进行调用的应用程序的线程中.确保多线程访问正确同步是用户的责任.非同步访问将导致 ConcurrentModificationException.

The Kafka consumer is NOT thread-safe. All network I/O happens in the thread of the application making the call. It is the responsibility of the user to ensure that multi-threaded access is properly synchronized. Un-synchronized access will result in ConcurrentModificationException.

更多详情请见 http://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#multithreaded

这篇关于当我使用 CuratorFrameworkFactory.newClient() 时,获取 KafkaConsumer 对于多线程访问错误是不安全的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆