Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
60 lines (54 loc) · 1021 Bytes

File metadata and controls

60 lines (54 loc) · 1021 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package chapter18;
/* J18_18.java */
/* Using Synchronized Method */
class Global // Global Class
{
synchronized void CallMe(String Msg) // Synchronized Method
{
System.out.print("[" +Msg);
try{
Thread.sleep(1000);
}
catch(Exception E)
{
System.out.print("Exception Caught.");
}
System.out.println("]");
}
}
class Caller implements Runnable // Caller Thread
{
String Msg;
Global Target;
Thread Th;
public Caller(Global Gb, String S)
{
Target = Gb;
Msg = S;
Th = new Thread(this);
Th.start();
}
public void run()
{
Target.CallMe(Msg);
}
}
public class J18_13 // Main Thread
{
public static void main(String args[])
{
Global Obj = new Global();
Caller Obj1 = new Caller(Obj, "Hello");
Caller Obj2 = new Caller(Obj, "Java");
Caller Obj3 = new Caller(Obj, "Programmer");
try{
Obj1.Th.join();
Obj2.Th.join();
Obj2.Th.join();
}
catch(Exception E)
{
System.out.println("Exception Caught.");
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.