利用多线程通信,实现两个线程,其中一个打印1-18,;另一个线程打印A-I,打印顺序为12A34B56C....1718I
public class Test1 {
static final Object object =new Object(); //共享对象,用来实现对象锁
public static void main(String[] args) {
new Thread(new Runnable() {
public void run() {
for(int i = 1; i <=18;i++) {
synchronized (object) {
if(i%2==0) {
System.out.print(i);
//唤醒线程2
object.notifyAll();
try {
//System.out.println("------线程1 开始等待");
//当前线程释放对象锁
object.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else {
System.out.print(i);
}
}
}
}}).start();
new Thread(new Runnable() {
char[] c = {'A','B','C','D','E','F','G'