Joerg Heinicke wrote:
On 26.05.2004 10:56, Ugo Cei wrote:
Sylvain Wallez wrote:
I was just looking in the VM spec if a increment operation on an integer is atomic or not. My opinion it has to be in the case of class members as the increment is surrounded by getfield/putfield instructions.
Accessing an "int" is atomic. Accessing a "long" is not. This is all from memory, which might fail, of course ... so let me see if I can dig up a reference...
But an increment is more than an access, isn't it?
It's three operations: read access, add one, write access. Thus, it is not atomic. Hence, synchronisation is required. That's the first question you ask when interviewing someone - what would unsynchronized counter in servlet show? And in EJB? :-)
Vadim
