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();
}
}

浙公网安备 33010602011771号