thread
共 1 篇文章
线程同步:生产者和消费者问题
1、实现一个生产者 public class Producer implements Runnable { SyncStack stack; //数据存放位置,和生产者是相同的位置 public Producer(SyncStack s){ stack = s; } public void run(){ for(int i=0; i<20; i++){ char c =(char)(Math.random()*26+'A'); stack.push(c);//产品生产后,存放产品 System.out.println("produced:"+c); try{ Thread.sleep((in…
2010-11-16 16:49 · thread · C · C++ · C# · thread