-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumTo100.java
More file actions
66 lines (53 loc) · 1.36 KB
/
SumTo100.java
File metadata and controls
66 lines (53 loc) · 1.36 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package PracticeQuestions;
public class SumTo100 {
static int count=0;
static final Object lock=new Object();
public static void main(String[] args) throws InterruptedException {
Thread t1=new Thread(()->{
synchronized (lock){
for (int i = 0; i < 1000 ; i++) {
count++;
}
}
});
Thread t2=new Thread(()->{
synchronized (lock){
for (int i = 0; i < 1000 ; i++) {
count++;
}
}
});
Thread t3=new Thread(()->{
synchronized (lock){
for (int i = 0; i < 1000 ; i++) {
count++;
}
}
});
Thread t4=new Thread(()->{
synchronized (lock){
for (int i = 0; i < 1000 ; i++) {
count++;
}
}
});
Thread t5=new Thread(()->{
synchronized (lock){
for (int i = 0; i < 1000 ; i++) {
count++;
}
}
});
t1.start();
t1.join();
t2.start();
t2.join();
t3.start();
t3.join();
t4.start();
t4.join();
t5.start();
t5.join();
System.out.println(count);
}
}