-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thread_Synchornization
78 lines (67 loc) · 980 Bytes
/
Thread_Synchornization
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
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.*;
class AdditionTable extends Thread{
synchronized void AddTable(int n) {
for(int i=0;i<10;i++)
{
System.out.println(n+"+"+i+"="+(n+i));
}
}
}
class AdditionTable1 extends Thread{
AdditionTable t;
int n;
AdditionTable1(AdditionTable t){
this.t=t;
}
public void run()
{
t.AddTable(n);
}
}
class AdditionTable2 extends Thread{
AdditionTable t;
int n;
AdditionTable2(AdditionTable t){
this.t=t;
}
public void run() {
t.AddTable(n);
}
}
public class ThreadSynchronization1 {
public static void main(String[] args) {
Scanner src=new Scanner (System.in);
AdditionTable a =new AdditionTable();
AdditionTable1 a1= new AdditionTable1(a);
AdditionTable2 a2 = new AdditionTable2(a);
a1.n=src.nextInt();
a2.n=src.nextInt();
a1.start();
a2.start();
}
}
/*
OUTPUT
-------
4 6
4+0=4
4+1=5
4+2=6
4+3=7
4+4=8
4+5=9
4+6=10
4+7=11
4+8=12
4+9=13
6+0=6
6+1=7
6+2=8
6+3=9
6+4=10
6+5=11
6+6=12
6+7=13
6+8=14
6+9=15
*/