?ai.set(ai.get()+1);
This is wrong because between the time when ai.get() returns a value and ai.set() is called, another thread may call increment and may get to execute ai.set with the same value. This will make you lose one increment.
Please be generous with your explanation.
The intention of your explanation should be helping people understand the concepts via your words.
Your purpose is not to save words.
You have very good materials and I commend your effort to come up with all these materials.
I greatly benefited from your materials for my Oracle Java Associate exam.
I'm not being bitchy. I just want you to get better and to get respect that you very much deserve for the work and the effort you put in.
If you have a tough time conveying your message, no one would understand you no matter how brilliant your work is.
Schmichael
P. S.
If saying too much does not get your point across, a couple of lines of code would do.
ai.set(ai.get()+1); // This is what's given.
For example,
Variable ai has a value of 5 originally.
ai.get() will return 5.
Before ai.set(5 + 1) happens,
"another thread may call increment and may get to execute ai.set with the same value."
I understand why another thread can come in between ai.get() and ai.set(5 + 1) because we are between 2 independent atomic operations.
"....and may get to execute ai.set with the same value." This part is very poorly written.
This was where I got stuck.