java如何设置死链大家帮看看哪里错了

来源:百度知道 编辑:UC知道 时间:2024/07/09 05:09:43

class ThreadDemo11
{
public static void main(String[] args)
{
TestThread tt=new TestThread();
new Thread(tt).start();
try
{
Thread.sleep(1);
}
catch (Exception e)
{
}
tt.str=new String("zhang xia");
new Thread(tt).start();
}
}
class TestThrea implements Runnable
{
private int i=100;
String str=new String("");
public void run()
{
if(str.equals("zhang xia"))
{
while(true)
{
see();
}
}
else
{
while(true)
{
synchronized (str)
{
if(i>0)
{
try
{
Thread.sleep(10);
}
catch (Exception e)
{
}
synchronized (this){}
System.out.println(Thread.currentThread().getName()+"The i is"+i--);
}
}
}
}<