package com.fengunion.dxc.pc;
import java.util.List;
public class Producer implements Runnable {
private List<String> list;
public Producer(List<String> list) { this.list = list; }
@Override public void run() { while (true){ synchronized (list){ if(list.size()==1){ System.out.println("队列已满...."); try { list.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } list.add("1"); list.forEach(x ->{ System.out.println("生产数据:"+x); }); list.notify(); } } } }
|