本帖最后由 袁野 于 2012-1-16 00:37 编辑
public class Demo0400
{
public static void main(String[] args)
{
Text0400 t = new Text0400();
Thread th1 = new Thread(t, "1111");
Thread th2 = new Thread(t, "2222");
th1.start();
th2.start();
}
};
class Text0400 implements Runnable
{
private int tick = 100;
Object obj = new Object();
public void run()
{
while (true)// 求这行代码的作用 ?
{
synchronized (obj) //为什么需要上面加个while (true) ;
{
if (tick > 0)
{
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()
+ "tick" + tick--);
}
}
}
}
};
while(true)的作用? |