Java Memory Model in few words

This article is mostly consist of quotes from The Well-Grounded Java Developer by Benjamin J. Evans and Martijn Verburg. I like simplicity and brevity of their explanation approach.

And that’s how Happens-Before and Synchronizes-With relationships are explained.


The JMM has these main rules:

The general statement of the first two rules is that “releases happen before acquires”. In other words, the locks that a thread holds when writing are released before the locks can be acquired by other operations (including reads).

There are additional rules, which are really about sensible behavior:


They even have granted free access to entire Chapter 4. Modern concurrency. Although I’m not relish with the code style (using trailing underscore to emphasize method parameters - why?) this chapter definitely deserves to read it.

Footnotes:

* JLS. Chapter 17. Threads and Locks assures that:

All actions in a thread happen-before any other thread successfully returns from a join() on that thread.

So, the truth is that thread actions happens-before Thread.join().


This is a post in the JMM series.
Other posts in this series:

Tags:
comments powered by Disqus