class Callme{
void call(String msg){
System.out.println("["+msg);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO: handle exception
System.out.println("Interrupted.");
}
System.out.println("]");
}
}
public class Caller implements Runnable {
String msg;
Callme target;
Thread t;
public Caller(Callme targ,String s) {
target=targ;
msg=s;
t=new Thread(this);
t.start();
}
@Override
public void run() {
target.call(msg);
// TODO Auto-generated method stub
}
}
class Synch
{
public static void main(String args[]){
Callme target=new Callme();
Caller ob[]={
new Caller(target, "Hellow"),
new Caller(target, "Synchronized"),
new Caller(target, "World")
};
try {
ob[0].t.join();
ob[1].t.join();
ob[2].t.join();
} catch (InterruptedException e) {
// TODO: handle exception
System.out.println("Interrupted.");
}
}
}