本帖最后由 pthuakai 于 2013-5-6 16:00 编辑
代码出错,求高手帮忙
package TestPackege;
class Testdemo3 implements Runnable
{
private boolean flag;
Testdemo3(boolean flag)
{
this.flag =flag;
}
public void run()
{
if(flag)
{
System.out.println("if locka");
synchronized(MyLock.locka)
{
System.out.println("if lockb");
}
}
else
{
synchronized(MyLock.lockb)
{
System.out.println("else lockb");
synchronized(MyLock.locka)
{
System.out.println("else locka");
}
}
}
}
}
class MyLock
{
static Object locka=new Object();
static Object lockb=new Object();
}
public class DeadLockTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread t1=new Thread(new Runnable(true));
Thread t2=new Thread(new Runnable(false));
t1.start();
t2.start();
}
}
|
|