Why does below snippet hang when i replace as.notify with as.notifyAll in main ?
public class abc {
/**
* @param args
*/
public static
String as = new String("");
public static void main(String[] args) {
new
Thread(new b()).start();
new Thread(new a()).start();
new Thread(new c()).start();
synchronized (as) {
as.notify();
}
System.out.println("Main khatam");
}
}
class a implements Runnable{
public void run(){
synchronized (abc.as) {
try {
abc.as.wait();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
Thread.sleep(new Double(Math.random()*1000).longValue());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("A");
synchronized (abc.as) {
abc.as.notify();
}
}
}
class b implements Runnable{
public void run(){
synchronized (abc.as) {
try {
abc.as.wait();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
Thread.sleep(new Double(Math.random()*1000).longValue());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("B");
synchronized (abc.as) {
abc.as.notify();
}
}
}
class c implements Runnable{
public void run(){
synchronized (abc.as) {
try {
abc.as.wait();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
Thread.sleep(new Double(Math.random()*1000).longValue());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("C");
synchronized (abc.as) {
abc.as.notify();
}
}
}