Merge pull request #8989 from alimate/BAEL-3866
BAEL-3866: Volatile Memory Ordering Example
This commit is contained in:
commit
1b6f7ed95e
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue