实现两个线程,一个线程打印1-52,另一个线程打印A-Z,要求输出的结果:
1 2 A 3 4 B 5 6 C 7 8 D 9 10 1112 ... 52 E F G H I J K ... X Y Z
package cn.edu.zzti.thread;
/**
* @author
* @version
* @date
* 打印1-52
*/
public class Thread52 extends Thread {
private Object object;
public Thread52(Object object){
this.object = object;
}
@Override
public void run(){
synchronized (object) {
for(int i = 1;i <= 52;i++){
System.out.print(i+" ");
if(i <= 8 && i%2 == 0){//如果i小于等于8切是偶数
object.notifyAll();//唤醒其他线程
try {
object.wait();//进入等待
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(i == 52){//如果i等于52,唤醒其他进程
object.notifyAll();
}
}
}
}
}
package cn.edu.zzti.thread;
/**
* @author