If there is a shared variable in my kafka streams application and that is updated by multiple threads in the processing code, how is that handled? Do I have to make that shared-variable thread safe or is that some how handled by the Kafka streams library? Somewhere in the docs, I read that there is no need to co-ordinate between threads when running a Kafka streams app. For example, here is a pseudo code:
KStream<byte[], byte[]> input = ...;
int counter = 0;
KStream<byte[], byte[]>[] processed = input.map(
(k, v) -> {
....
....
//update counter by multiple threads.
);
What will happen to counter if this code is executed by multiple stream tasks from the same app instance? How about the variable "processed" as this can also be updated by multiple threads? This requires some kind of synchronization in normal Java scenario. I am curious if that is handled by the Kafka streams library.
Thank you!