I believe X++; should also work fine because there is just one step which does not need any sequencing meaning no synchronization.
Originally posted by Henry Wong:
Unfortunately, this is not true. There is no increment opcode, in the Java bytecode instruction set. The JIT may compile it to one, but there is no guarantee that this will be enforced by the specification.
To do what you want... take a look at the atomic variables.
These variables provide simple (which can be built upon) access to variables, in a fashion that doesn't need any synchronization.
[Abhijit]: Thnx Henry but these atomic variables you talking about may internally use sync blocks.
[Jim]: Except that they don't. You can investigate the source code yourself if you like.
Originally posted by Abhijit Choudhury:
Thanks a lot Henry and Jim