forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSync.java
More file actions
57 lines (51 loc) · 1.07 KB
/
Sync.java
File metadata and controls
57 lines (51 loc) · 1.07 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
package multithreading;
public class Sync {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("<< HOME ADDRESS IS >>");
Call c = new Call();
@SuppressWarnings("unused")
Synchro s = new Synchro(c,"VRAJBHUMI");
@SuppressWarnings("unused")
Synchro s1 = new Synchro(c,"AMBAWADI PLOT");
@SuppressWarnings("unused")
Synchro s2 = new Synchro(c,"MADHAVANAGAR");
@SuppressWarnings("unused")
Synchro s3 = new Synchro(c,"MALIYA-HATINA");
}
}
class Call
{
synchronized void disp(String s){
System.out.print("\""+s);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO: handle exception
System.out.println(e);
}
System.out.println("\"");
}
}
class Synchro implements Runnable
{
Call c;
String s;
public Synchro(Call c, String s) {
// TODO Auto-generated constructor stub
this.c = c;
this.s = s;
Thread t = new Thread(this);
t.start();
}
public void run() {
// TODO Auto-generated method stub
c.disp(s);
/*synchronized (c) {
c.disp(s);
}*/
}
}