Page 1 of 1
About Question enthuware.ocpjp.v7.2.1083 :
Posted: Fri May 30, 2014 4:55 am
by kashyapa
why this is wrong????

Re: About Question enthuware.ocpjp.v7.2.1083 :
Posted: Fri May 30, 2014 11:32 am
by admin
The whole purpose of using AtomicInteger is to increment atomically i.e. in a single operation. In this option, you are incrementing ai in two separate calls, which is not thread safe. Between the time when ai.get() returns a value and ai.set() is called, some other thread may call ai.set with the same value. This will make the count incorrect.
HTH,
Paul.