RedSpider1 / concurrent

这是RedSpider社区成员原创与维护的Java多线程系列文章。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

阻塞队列这章中的例子说System.out.println语句没有加锁,但是println不是加锁的吗

likuisuper opened this issue · comments

第三章-JDK工具篇-阻塞队列中,那个生产者消费者的例子中,说了输出的结果有问题,是因为由于System.out.println语句没有锁,但是println中不是使用synchronized来保证同步了吗?
public void println(int x) {
synchronized (this) {
print(x);
newLine();
}
}

这里应该是指的queue操作和打印操作没有一起上锁,导致打印结果看起来不太正常。后续改下描述。

已修改