public synchronized void set(String name)// t0 t1
{
if(flag)
{
try{this.wait();}catch(InterruptedException e){}
}
this.name = name;
count++;
System.out.println(Thread.currentThread().getName()+":生产者:"+name+count);
flag = true;
this.notify();
}
假如t0线程持有锁进入同步函数中,那么等他wait();之后这个锁是怎么处理的呢? |
|