I know this question was asked before here: Kafka Streaming Concurrency?
But yet this is very strange to me. According to the documentation (or maybe I am missing something) each partition has a task meaning different instance of processors and each task is being execute by different thread. But when I tested it, I saw that different threads can get different instances of processor. Therefore if you want to keep any in memory state (old fashioned way) in your processor you must lock?
Example code:
public class SomeProcessor extends AbstractProcessor<String, JsonObject> {
private final String ID = UUID.randomUUID().toString();
@Override
public void process(String key, JsonObject value) {
System.out.println("Thread id: " + Thread.currentThread().getId() +" ID: " + ID);
OUTPUT:
Thread id: 88 ID: 26b11094-a094-404b-b610-88b38cc9d1ef
Thread id: 88 ID: c667e669-9023-494b-9345-236777e9dfda
Thread id: 88 ID: c667e669-9023-494b-9345-236777e9dfda
Thread id: 90 ID: 0a43ecb0-26f2-440d-88e2-87e0c9cc4927
Thread id: 90 ID: c667e669-9023-494b-9345-236777e9dfda
Thread id: 90 ID: c667e669-9023-494b-9345-236777e9dfda
Is there a way to enforce thread per instance ?