【发布时间】:2011-09-21 02:28:36
【问题描述】:
def append(msg: Msg, session: OutputChannel[Any]) {
changeSize(1) // size always increases by 1
val el = new MQueueElement(msg, session)
if (isEmpty) first = el
else last.next = el
last = el
}
MQueue(actor 的消息队列)的 append 方法没有最大大小。这不会导致内存不足吗?
并查看 changeSize(1)
private var _size = 0
def size = _size
final def isEmpty = last eq null
protected def changeSize(diff: Int) {
_size += diff
}
为什么不用 @volatile 和私有 var _size ?
如果追加时间超过 Int.maxValue 怎么办?
我们只是期望那些永远不会发生吗?
【问题讨论】: