import java.util.concurrent.locks.LockSupport;
/**
* @ProjectName traffic
* @ClassName LockSupportTest
* @Desicription TODO
* @Author Zhang Xueliang
* @Date 2019/10/31 17:06
* @Version 1.0
**/
public class LockSupportTest {
final static char[] cI = "1234567".toCharArray();
final static char[] cC = "ABCDEFG".toCharArray();
static Thread t1 =null;
static Thread t2 =null;
public static void main(String[] args) {
t1 = new Thread(()->m1());
t2 = new Thread(()->m2());
t1.start();
t2.start();
}
public static void m1(){
for (char c : cI) {
LockSupport.unpark(t2);
System.err.print(c);
LockSupport.park();
}
}
public static void m2(){
for (char c : cC) {
LockSupport.park();
System.err.print(c);
LockSupport.unpark(t1);
}
}
}