java多线程 为什么这里结果为12A然后后边就不打印了,求指点
package homework11;
/*
* 1.编写两个线程,一个线程打印1-52的整数, 另一个线程打印字母A-Z
* 打印的顺序四
* 12A34B56C...52Z
*/
public class homework11 {
public static void main(String[] args) {
Thread threadA = new Thread(new Runnable() {
@Override
public synchronized void run() {
int i=1;
while(i<=52){
System.out.print(i);
if(i%2==0) {
notify();
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
i++;
}
}
});
Thread threadB = new Thread(new Runnable() {
@Override
public synchronized void run() {
char c='A';
while(c<=(char)90) {
System.out.print(c);
notify();
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c=(char)(c+1);
}
}
});
threadA.start();
try {
Thread.sleep(10);//保证初始的线程执行顺序:A->B
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
threadB.start();
}
}
运行结果
