pro1:
public class AA implements Runnable{
String ss=new String();
public void f(){
synchronized(ss){
try {System.out.println("hello");wait();}catch(Exception e){}
}}
public void run(){f();}
public static void main(String[] args) {
AA a =new AA();
new
Thread(a,"no1").start();
new Thread(a,"no2").start();
}}
the output is :
hello
hello
and then program ends.
Why end???the two are both in wait state ,I think. but
pro2:
public class AA implements Runnable{
String ss=new String();
public void f(){
synchronized(this){
try {System.out.println("hello");wait();}catch(Exception e){}
}}
public void run(){f();}
public static void main(String[] args) {
AA a =new AA();
new Thread(a,"no1").start();
new Thread(a,"no2").start();
}}
output is
hello
hello
and program does not end.
I am wondering about the lock, what the different effect between this and other object lock.
Thank you!
[ August 12, 2004: Message edited by: Ning Zhuang ]