Dalvik VM & Java Memory Model (Concurrent programming on Android)

I haven’t read your question completely, but first of all do not use volatile, even opengles coders do not use it for different ui vs renderer threads. Use volatile if and only if one thread writes (say to some class’ static property) and other reads, even then you have to synchronize, read this for some … Read more

What are the similarities between the Java memory model and the C++11 memory model?

The Java memory model was an important influence on the C++11 memory model, and was where we pulled the terms happens-before and synchronizes-with from. However, the C++11 memory model offers much more fine-grained control over memory ordering than the Java memory model. Java volatile variables are equivalent to C++11 std::atomic<> variables, if you use std::memory_order_acquire … Read more

Must all properties of an immutable object be final?

The main difference between an immutable object (all properties final) and an effectively immutable object (properties aren’t final but can’t be changed) is safe publication. You can safely publish an immutable object in a multi threaded context without having to worry about adding synchronization, thanks to the guarantees provided by the Java Memory Model for … Read more

Why is `synchronized (new Object()) {}` a no-op?

The FAQ is not the authority on the matter; the JLS is. Section 17.4.4 specifies synchronizes-with relationships, which feed into happens-before relationships (17.4.5). The relevant bullet point is: An unlock action on monitor m synchronizes-with all subsequent lock actions on m (where “subsequent” is defined according to the synchronization order). Since m here is the … Read more