Topic: 能帮我看看这个模拟生产者消费者的程序错在哪了吗

  Print this page

1.能帮我看看这个模拟生产者消费者的程序错在哪了吗 Copy to clipboard
Posted by: learner
Posted on: 2009-04-25 21:57

它有时候会出现还没生产就先消费了的情况,为什么啊

ProducerConsumer.java (1.6k)

2.Re:能帮我看看这个模拟生产者消费者的程序错在哪了吗 [Re: learner] Copy to clipboard
Posted by: huxiaowei
Posted on: 2009-05-01 14:06

再仔细看下你的RUN方法,里面的生产语句与打印语句也应该是一个原子操作

3.Re:能帮我看看这个模拟生产者消费者的程序错在哪了吗 [Re: learner] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2009-05-01 23:46

Exactly, the System.out.println() statement is not protected by the synchronized block, which means the println() is not thread safe.

Regards,
Jiafan


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923