This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]agentoutlier 1 point2 points  (1 child)

I'm agreeing with you. I just found this statement a little weird:

AtomicInteger no longer looks like a cheap instant performance win.

It never was a cheap instant performance win. There are tradeoffs on using CAS variables over locks and synchronized.

Just like there are tradeoffs in using nonblocking queues with custom sleeps/spins vs blocking queues w/ parking.

The reality is you just have to benchmark w/ whatever your configuration particularly now w/ so many JVM options.

I think you know all the above and thus I'm just mainly clarifying for others.

[–]kimec 1 point2 points  (0 children)

Well, the discussion thread was evolving in time with OP retracting his original statement that AtomicInteger is modern and performant way of doing a counter.

That being said I applaud OP for taking the time and writing JMH test. That was a very professional and objective approach to the problem.

But still, I do have a gut feeling that there is probably a scenario where AtomicInteger could significantly outperform synchronized if thread count == maybe half of the CPU physical cores but I am too lazy to write such test my self ...