Tags

links:
– Effective Java 2nd Edition by Joshua Bloch
http://stackoverflow.com/questions/8334800/multiple-threads-reading-a-variable
http://www.vogella.com/articles/JavaConcurrency/article.html

summary:
– in java, all variable atomic except long or double
– atomic meaning no half and half value, but can’t tell which thread wrote what
– “The language specification gaurantees that reading or writing a variable is atomic unless the variable is of type long or double[JLS, 14.4.7].”
– Java 1.5 atomic variables, e.g. AtomicInteger, AtomicLong, getAndDecrement(), getAndIncrement() and getAndSet() which are atomic.
– example from vogella, i++ is _not_ atomic, cuz it’s 2 atomic steps consisting load and assign.

Advertisements