public class Demo {
static boolean flag = false;
static int count = 1;
public static void main(String[] args) throws InterruptedException {
new Thread(new Runnable() {
@Override
public void run() {
while (true)
if (flag)
synchronized (Demo.class) {
System.out.println(“播放背景音乐” + count++);
flag1 = false;
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
while (true)
if (!flag)
synchronized (Demo.class) {
System.out.println(“显示画面” + count++);
flag = true;
}
}
}).start();
}
}
小白求问 我这代码为啥会出现死锁
最新推荐文章于 2022-05-29 16:06:09 发布