Tutorial by Examples

Consider the following example: public class Example { public int a, b, c, d; public void doIt() { a = b + 1; c = d + 1; } } If this class is used is a single-threaded application, then the observable behavior will be exactly as you would expect. For instan...
(The following is a simplified version of what the Java Language Specification says. For a deeper understanding, you need to read the specification itself.) Happens-before relationships are the part of the Memory Model that allow us to understand and reason about memory visibility. As the JLS say...
We will present some examples to show how to apply happens-before reasoning to check that writes are visible to subsequent reads. Single-threaded code As you would expect, writes are always visible to subsequent reads in a single-threaded program. public class SingleThreadExample { public in...
The Memory Model is difficult to understand, and difficult to apply. It is useful if you need to reason about the correctness of multi-threaded code, but you do not want to have to do this reasoning for every multi-threaded application that you write. If you adopt the following principals when wri...

Page 1 of 1