-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSynchronized_2.java
More file actions
51 lines (44 loc) · 1.03 KB
/
Synchronized_2.java
File metadata and controls
51 lines (44 loc) · 1.03 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* JAVA MULTITHREAD - Synchronized - Uso mais real
*
* @author RinaldoDev
*/
public class Synchronized_2 {
private static int i = 0;
public static void main(String[] args) {
MeuRunnable runnable = new MeuRunnable();
Thread t0 = new Thread(runnable);
Thread t1 = new Thread(runnable);
Thread t2 = new Thread(runnable);
Thread t3 = new Thread(runnable);
Thread t4 = new Thread(runnable);
t0.start();
t1.start();
t2.start();
t3.start();
t4.start();
}
public static class MeuRunnable implements Runnable {
@Override
public void run() {
int j;
synchronized (this) {
i++;
j = i * 2;
}
double jElevadoA100 = Math.pow(j, 100);
double sqrt = Math.sqrt(jElevadoA100);
System.out.println(sqrt);
}
}
}
//
// picpay.me/RinaldoDev
// apoia.se/rinaldodev
//
// YouTube: RinaldoDev
// Twitter: @rinaldodev
// Blog: rinaldo.dev
// LinkedIn: rinaldodev
// Facebook: rinaldo.dev
//