Here is my scenario:
I have a master actor who receives messages from several child actors. These messages contain data for aggregation. In this aggregation logic, do I need to take care of synchronization issues if I use a common data structure to collect aggregation?
else if(arg0 instanceof ReducedMsg){
ReducedMsg reduced = (ReducedMsg)arg0;
counter.decrementAndGet();
synchronized(finalResult){
finalResult.add((KeyValue<K, V>) reduced.getReduced());
if(counter.get() == 0){
if(checkAndReduce(finalResult)){
finalResult.clear();
}
else{
stop();
latch.countDown();
}
}
}
}
So, as you can see, I have finalResult for which each message will be aggregated, and after the processing logic the collection should also be cleared.
In fact, what I'm trying to implement is a recursive (associative) reduction of mapreduce. So I need to keep the synchronized block, which I assume? Or is it by accident that Akka executes onReceive one thread at a time?
. , , . , - , dwelve .