【问题标题】:Why the scala actor message queue have no bound(size)为什么 scala 演员消息队列没有界限(大小)
【发布时间】: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 怎么办?
我们只是期望那些永远不会发生吗?

【问题讨论】:

    标签: scala actor


    【解决方案1】:

    对于您问题的第一部分:是的,另请参阅此相关问题Actors Mailbox Overflow. Scala

    我认为 _size 变量没有被标记为 volatile,因为这里期望调用方法负责同步。我简要浏览了代码,调用此方法的演员库的各个部分确实被标记为同步。 对于整数溢出:我想确实预计这永远不会发生。 最常用的 Actor 库是 Akka,它确实支持有界邮箱,请参阅 this link 了解语义和配置。除此之外,它们将替换/合并到 scala 发行版中的演员库:as discussed recently on the mailing list

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      • 2011-12-05
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      相关资源
      最近更新 更多