If i have this synchronized code which i want to replace with actors with no synchronization, how?
public synchronized int incrementAndGet() {
i = i + 1;
return i;
}
and i have a bunch of users in web site where i need to return each an incrementing number…
how can i replace that code with actors code which have no synchronizations thus have no blocking synchronizing code. which i guess would thenn be able to run it on multicores etc (isn’t that the purpose of actors?).
A simple actor wrapping
iin its internal state:And blocking usage (you need to obtain
incrementAndGetsomehow):This code is: slow, complicated and non-idiomatic. What about
AtomicInteger?