Originally posted by Sunny Jain:
I was reading the concurrency from Sun tutorial, I don't find it much useful, Whatever it provides we can achieve the same through Synchronization, I think using sync is much easier to understand, Can anyone tell me..in which condition i should use Atomic integer rather than Synchronization ?
why atomic_a is giving result as 4 always.
line 2 is executed exactly 4 times before line 3 get executed. In most of the case in the order in which line 2 was executer was preserved, but that was not the case always, but always one line is executed by each thread before the next line.assume all line atomic operation.
I am just confuse how all this happening?
following two code will performs equally, Then why should i go for atomic integer rather than simple integer, as far as i think, atomic integer is the Object and normal int is primitive so primitive is lighter on JVM rather than Object.