Simple question, for the sake of theory, and could not find anything that addressed this particular usecase:
One method, called by 40 000 Threads ( For the sake of being relevant question )
public void synced() {
synchronized(lock) { number *= 1.23; }
}
public void atomic() {
number.updateAndGet(n -> n*1.23)
}
Which one is likely to cause less issues here?
I am thinking that the atomic method would, since updateAndGet uses a while loop internally and if we have high access to the updateAndGet method, many threads could end up in that while loop, and possibly exiting very late in worst case scenario, if at all.
The first case won't, although lack of a fairness policy could prevent it from running late as well.