For those who are curious...
Here is a class that compares the behavior of a unary ++ operation on a primitive integer and the corresponding method in java.util.concurrent.atomic.AtomicIntege
r when they are accessed by concurrent threads.
java -classpath
atom.jar Atom 10 1000
This will start 10 threads, let them run for approximately 1000 milliseconds and print the shared primitive and atomic counters, the sum of individual counters for all threads, and the differences.
Requires Java 5.
On a 2GHz Windows 2000 workstation, the primitive integer is off about half of the time, and on a multiprocessor Linux server, every time I tried, even with 2 threads and 100 ms.
( Read more...Collapse )