62,614
社区成员
发帖
与我相关
我的任务
分享
class test implements Runnable{
private boolean flag;
public test(boolean flag){
this.flag=flag;
}
public void run(){
if(flag){
synchronized (Mylock.locka) {
System.out.println("if locka");
synchronized (Mylock.lockb) {
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{
public static void main(){
Thread t1=new Thread(new test(true));
Thread t2=new Thread(new test(false));
t1.start();
t2.start();
}
}
想写个死锁,控制台输出一堆乱码 请问怎么回事