-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
35 lines (26 loc) · 854 Bytes
/
Main.java
File metadata and controls
35 lines (26 loc) · 854 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
public class Main {
public static void main(String[] args) throws InterruptedException {
Counter count=new Counter(0);
Runnable myThread1 = ()->{
for (int i = 0; i <10 ; i++) {
count.increment();
System.out.println(count.getCountValue()+ " value from increment");
}
};
myThread1.run();
Thread t1=new Thread(myThread1);
t1.start();
Runnable myThread2=()->{
for (int i = 0; i <10 ; i++){
count.decrement();
System.out.println(count.getCountValue()+ " value from decrement");
}
};
myThread2.run();
Thread t2=new Thread(myThread2);
t2.start();
t1.join();
t2.join();
System.out.println(count.getCountValue()+ " value from Main");
}
}