1. LockSupport
package com.example.demo;
import java.util.concurrent.locks.LockSupport;
public class PrintA1B2 {
static Thread t1 = null;
static Thread t2 = null;
public static void main(String[] args) {
char[] num = "1234567".toCharArray();
char[] str = "ABCDEFG".toCharArray();
t1 = new Thread(()->{
for (char n:num
) {
System.out.println(n);
LockSupport.unpark(t2);
LockSupport.park();
}
},"t1");
t2 = new Thread(()->{
for (char s:str) {
LockSupport.park();
System.out.println(s);
LockSupport.unpark(t1)