Borrowing one Example from JCIP

This commit is contained in:
Ali Dehghani 2020-03-30 01:29:02 +04:30
parent f79cdee39a
commit 35bbf9c884
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;
}
}