1

package com.cntaiping.tpi.claimplat.serviceapi.Test8.Lambda;

public class Demo01 {

private static boolean b = false;
public static void main(String[] args) {
new Thread(()->{
while(true) {
synchronized (Demo01.class) {
if(b) {
try {
Demo01.class.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("线程111执行");
b = true;
Demo01.class.notify();
}
}
}
) .start();

new Thread(()->{
while(true) {
synchronized (Demo01.class) {
if(!b) {
try {
Demo01.class.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("线程222执行");
b = false;
Demo01.class.notify();
}
}
}
) .start();


}

}

posted @ 2021-05-26 11:15  步江伍德  阅读(54)  评论(0)    收藏  举报