-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathVolatile.java
More file actions
37 lines (33 loc) · 737 Bytes
/
Volatile.java
File metadata and controls
37 lines (33 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* JAVA MULTITHREAD - Volatile e Yield
* @author RinaldoDev
*/
public class Volatile {
private static int numero = 0;
private static boolean preparado = false;
private static class MeuRunnable implements Runnable {
@Override
public void run() {
while (!preparado) {
Thread.yield();
}
System.out.println(numero);
}
}
public static void main(String[] args) {
Thread t0 = new Thread(new MeuRunnable());
t0.start();
numero = 42;
preparado = true;
}
}
//
// picpay.me/RinaldoDev
// apoia.se/rinaldodev
//
// YouTube: RinaldoDev
// Twitter: @rinaldodev
// Blog: rinaldo.dev
// LinkedIn: rinaldodev
// Facebook: rinaldo.dev
//