关于线程的一个问题
public class ThreadA
{
public static void main(String[] args)
{
ThreadB b=new ThreadB();
b.start();
System.out.println("b is start....");
synchronized(b)
{
try
{
System.out.println("Waiting for b to complete...");
b.wait();//没有被notify,它为什么还能被唤醒呢?
System.out.println("Completed.Now back to main thread");
}catch (InterruptedException e){System.out.println("interrupted!");}
}
System.out.println("Total is :"+b.total);
}
}
class ThreadB extends Thread
{
int total;
public void run()
{
synchronized(this)
{
System.out.println("ThreadB is running..");
for (int i=0;i<100;i++ )
{
total +=i;
System.out.println("total is "+total);
}
//notify(); 这里没有Notify
}
}
}
wait()的作用是这样说的,Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
但是这里没有对b Notify啊,为什么线程还是被唤醒了?