-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockSynchronization.java
More file actions
58 lines (58 loc) · 1022 Bytes
/
Copy pathBlockSynchronization.java
File metadata and controls
58 lines (58 loc) · 1022 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Table
{
void printTable (int n)
{
synchronized (this)
{
for (int i=1; i<=5; i++)
{
{
System.out.println (n*i);
}
try
{
Thread.sleep (400);
}
catch (Exception e)
{
System.out.println (e);
}
}
}
}
}
class MyThread1 extends Thread
{
Table t;
MyThread1 (Table t)
{
this.t = t;
}
public void run()
{
t.printTable(5);
}
}
class MyThread2 extends Thread
{
Table t;
MyThread2 (Table t)
{
this.t = t;
}
public void run ()
{
t.printTable(100);
}
}
class Main
{
public static void main (String args[])
{
Table obj = new Table();
MyThread1 t1 = new MyThread1(obj);
MyThread2 t2 = new MyThread2(obj);
t1.start();
t2.start();
}
}