Merge pull request #8989 from alimate/BAEL-3866

BAEL-3866: Volatile Memory Ordering Example
This commit is contained in:
Eric Martin 2020-04-06 22:03:34 -05:00 committed by GitHub
commit 1b6f7ed95e
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package com.baeldung.concurrent.volatilekeyword;
public class TaskRunner {
private static int number;
private volatile static boolean ready;
private static class Reader extends Thread {
@Override
public void run() {
while (!ready) {
Thread.yield();
}
System.out.println(number);
}
}
public static void main(String[] args) {
new Reader().start();
number = 42;
ready = true;
}
}