我是一个初学java的小鸟,望大家指点,
代码如下,请帮忙找一下错误地方,
public class Read{
int a;
boolean b;
public static void main (String[] args) throws Exception {
Producer s=new Producer();
Consumer r=new Consumer();
Thread t1=new Thread(s);
Thread t2=new Thread(r);
t1.start();
t2.start();
}
class Producer implements Runnable{
public void run(){
while(b){
try{
wait();
}catch(InterruptedException e){
e.printStackTrace();
}
}
a=(int)(Math.random()*256);
System.out.println("数据已送出!!.....");
b=false;
this.notify();
}
}
class Consumer implements Runnable{
public void run(){
while(!b){
try{
wait();
}catch(InterruptedException e){
e.printStackTrace();
}
}
System.out.println("输出数据:"+a);
b=true;
this.notify();
}
}
}