hi all
I found this question i one of the mock exams and was not able to get the output ..
code:
class Test implements Runnable {
public void run() {
String str = new String("Hello");
synchronized(str){
try
{
System.out.println(Thread.currentThread().getName());
Thread.sleep(5000);
System.out.println(Thread.currentThread().getName());
}
catch(InterruptedException e){}
}
}
}
public static void main(String args[])
{
new Thread(new Test(),"A").start();
new Thread(new Test(),"B").start();
}
}
Thanks in advance.
I found this question i one of the mock exams and was not able to get the output ..
code:
class Test implements Runnable {
public void run() {
String str = new String("Hello");
synchronized(str){
try
{
System.out.println(Thread.currentThread().getName());
Thread.sleep(5000);
System.out.println(Thread.currentThread().getName());
}
catch(InterruptedException e){}
}
}
}
public static void main(String args[])
{
new Thread(new Test(),"A").start();
new Thread(new Test(),"B").start();
}
}
Thanks in advance.