程序原意是需要发送进程与接受进程交替按顺序执行,可是每次运行结果就是只执行了发送进程,
而接受进程没有执行,请问是什么原因?不胜感激!!!代码如下:
   package Distribute;public class Buffer {
public int value; public boolean isEmpty1 = true; synchronized void put(int i) {
while (!isEmpty1) {
try {
this.wait();
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
value = i;
isEmpty1 = false;
notify();

}
} synchronized int get() {
while (isEmpty1) {
try {
this.wait();
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
}
isEmpty1=true;
notify();
return value;
}
}
public class Sender extends Thread { /**
 * @param args
 */
private Buffer bf;
public Sender(Buffer bf){
this.bf=bf;
}
public void run(){
for(int i=1;i<17;i++){
bf.put(i);
System.out.println("Sender put"+i);
}
}

public static void main(String[] args) {
System.out.println("entry\n");
Buffer bf=new Buffer();
(new Sender(bf)).start();
Thread ta[]=new Thread[40];
Thread.enumerate(ta);
for(int j=0;j<Thread.activeCount();j++)
System.out.println(ta[j].getName()+"  "+ta[j].isAlive());
(new Receiver1(bf)).start();
Thread tb[]=new Thread[40];
Thread.enumerate(tb);//to copy the current thread to the array ta[];
for(int j=0;j<Thread.activeCount();j++)
System.out.println(tb[j].getName()+"  "+tb[j].isAlive());
}}
public class Receiver1 extends Thread{
private Buffer bf;
public Receiver1(Buffer bf){
this.bf=bf;
}
public void run(){
for(int i=1;i<17;i++){
System.out.println("\t\t Receiver get:"+bf.get());}
}}