Getting KafkaConsumer is not safe for multi-threaded access error when I use CuratorFrameworkFactory.newClient()

edrichhans picture edrichhans · Dec 19, 2018 · Viewed 8.6k times · Source

I am receiving this error below:

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?

Thanks.

Answer

Sammy picture Sammy · Dec 19, 2018

Kafka Javdocs clearly mentions that :

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.

More details present at http://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#multithreaded