MENU

Fun & Interesting

Java Happens Before Guarantee - Java Memory Model - Part 2

Jakob Jenkov 67,290 5 years ago
Video Not Working? Fix It Now

The Java Happens Before Guarantee is a set of rules that restrict instruction reordering to make sure that instruction reordering does not break the Java visibility guarantees. Breaking the visibility guarantees (of data shared between threads) would make thread communication in Java much less reliable, and thus harder to get right. The Java Happens Before Guarantee counters that. Chapters: 0:00 Java Happens Before Guarantee - Introduction 0:34 Instruction reordering explained 3:42 Instruction reordering may affect visibility of changes to objects shared between threads 7:04 The visibility guarantee of volatile variables 11:18 Instruction reordering may break the volatile visibility guarantee 14:10 Volatile happens before guarantee 17:08 Synchronized visibility guarantee 20:09 Instruction reorderingmay break the synchronized visibility guarantee 22:45 Synchronized happens before guarantee 25:06 Further notes Java Memory Model - JSR 133 https://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html Here is a textual version of this Java Happens Before Guarantee tutorial: http://tutorials.jenkov.com/java-concurrency/java-happens-before-guarantee.html The Java Happens Before Guarantee is part of the Java Memory Model. I have an introduction to the Java Memory Model (link below) which content I assume you are reasonably familiar with (thread stacks and the heap) before watching this video. https://www.youtube.com/watch?v=LCSqZyjBwWA Java Concurrency video playlist: https://www.youtube.com/playlist?list=PLL8woMHwr36EDxjUoCzboZjedsnhLP1j4 Java Concurrency textual tutorials: http://tutorials.jenkov.com/java-concurrency/index.html

Comment