看看下面的代码会发生死锁的情况吗?
我的机子试了好几次也没出现死锁的情况。
class Thread_1 implements Runnable
{
Object obj = new Object();
int i = 1000;
public synchronized void show2()
{
//while(i>0)
while(true)
{
synchronized(obj)
{
System.out.println(Thread.currentThread().getName()+" "+i);
i--;
}
}
}
public void run()
{
//while(i>0)
while(true)
{
synchronized(obj)
{
show2();
}
}
}
}
public class ThreadTest
{
public static void main(String[] args)
{
Thread_1 t = new Thread_1();
new Thread(t).start();
new Thread(t).start();
}
}
|
|