-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonSynchronized.java
More file actions
37 lines (33 loc) · 824 Bytes
/
NonSynchronized.java
File metadata and controls
37 lines (33 loc) · 824 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
class CallMe {
void call(String msg) {
System.out.print("[" + msg);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Interrupted");
}
System.out.println("]");
}
}
class Caller implements Runnable {
String msg;
CallMe target;
Thread t;
public Caller(CallMe c, String s) {
target = c;
msg = s;
t = new Thread(this);
t.start();
}
public void run() {
target.call(msg);
}
}
public class NonSynchronized {
public static void main(String[] args) {
CallMe target = new CallMe();
Caller ob1 = new Caller(target, "Hello");
Caller ob2 = new Caller(target, "Synchronized");
Caller ob3 = new Caller(target, "World");
}
}