class thr2
{
public static void main(String args[])
{
A a = new A("first","hello1");
A a1= new A("second","hello2");
try{
a.t.join();
a1.t.join();
}catch(Exception e)
{
}
}
}
class A implements Runnable
{
Thread t;
String str;
B b = new B();
A(String name,String str)
{
t=new Thread(this,name);
t.setName(name);
this.str=str;
t.start();
}
public void run()
{
b.sum(str);
}
}
class B
{
synchronized void sum(String str)
{
System.out.print("[" + str);
try
{
Thread.sleep(100);
}catch(Exception e)
{
}
System.out.println("]");
}
}
when synchronized with sum() is used then output is same when it is not there. tell me y it is not working here?