2018.1.22
class producer implements Runnable{
int ms,n;
producer(int ms,int n){
this.ms = ms;
this.n=n;
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
try {
while (count<stop) {
produce();
Thread.sleep(ms);
}
}
catch (Exception e){
e.printStackTrace();
}
}
void produce() throws Exception {
synchronized (queue){
for(int i=0;i<n;i++) {
if(count >= max)
break;
queue.add(count);
textView.setText(textView.getText().toString()+Thread.currentThread().getName()+" 生产了:"+count+"还剩:"+queue.size()+'\n');
count++;
}
}
}
}