本帖最后由 daoyua 于 2014-1-10 16:27 编辑
public synchronized void run(){
while(num>0){
if(num>0){
System.out.println(Thread.currentThread().getName()+"同步函数"+num);
num--;
}
}
}
class Test
{
public static void main(String args[])
{
Demo d1=new Demo();
Thread t1=new Thread(d1);
Thread t2=new Thread(d1);
t1.start();
t2.start();
}
} |