`
cywhoyi
  • 浏览: 413398 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

calculator

    博客分类:
  • JAVA
阅读更多
package thread.stack;

/**
* 消费者类
* @author KF24527/Peter
*/
public class Consumer implements Runnable {

private Stack stack;

/**
* 生产者构造方法
*/
public Consumer(Stack stack) {
this.stack = stack;
}

/**
* 消费商品方法
*/
public void con() {
char c;

for (int i = 0; i < 200; i++) {

// 集合(堆栈)中输出元素
c = stack.pop();

// 当前线程的名字
String threadName = Thread.currentThread().getName();

System.out.println("消费者" + threadName + ":" + "消费了字符" + c);

try {

// 等待30毫秒
Thread.sleep(30);
} catch (Exception e) {
e.printStackTrace();
}
}

}

public void run() {
this.con();
}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics