Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Akka-超出GC开销限制_Java_Scala_Akka - Fatal编程技术网

Java Akka-超出GC开销限制

Java Akka-超出GC开销限制,java,scala,akka,Java,Scala,Akka,我得到一个: java.lang.OutOfMemoryError: GC overhead limit exceeded at java.nio.HeapByteBuffer.asReadOnlyBuffer(HeapByteBuffer.java:117) at akka.util.ByteString$ByteString1.asByteBuffer(ByteString.scala:153) at akka.util.ByteString$ByteString1C

我得到一个:

java.lang.OutOfMemoryError: GC overhead limit exceeded
    at java.nio.HeapByteBuffer.asReadOnlyBuffer(HeapByteBuffer.java:117)
    at akka.util.ByteString$ByteString1.asByteBuffer(ByteString.scala:153)
    at akka.util.ByteString$ByteString1C.asByteBuffer(ByteString.scala:104)
使用此Akka代码:

  var buffer = ByteString.apply()
  val MsgSize = 208

  protected def onMessage(rawMsg: ByteString) = {

    // Messages under the size are not processed in while loop.  This line appends them
    // to be processed when enough data is present.
    buffer ++= rawMsg

    // Process multiple messages if present.
    while (buffer.size >= MsgSize) {
      // Process each message, leaves remainder for later processing.
    }

    // To prevent the buffer from growing uncontrollably.
    // It is possible that at some point this fails to run for a long time 
    // which could cause the out of memory exception.
    if (buffer.isEmpty) buffer = ByteString.apply()
  }

看起来连接可能是问题所在。这是正确的方法吗?

事实证明我们必须这样做:

while (buffer.size >= MsgSize) {
  val (msg, rem) = buffer.splitAt(MsgSize)

  // Process msg

  // buffer is now what remains
  buffer = rem
}

因为从缓冲区读取不会增加位置。

缓冲区是否会在某个点减少或清空?可能是环路?在我看来,这不是保证。您是否可以使用更严格定义的消息类型,而不影响字节?即使有注释,我也看不到if(buffer.isEmpty)buffer=ByteString.apply()的意义。此外,您还说您处理多条消息(如果存在)。缓冲区中不应存在多条消息的情况。您可以自行处理rawMsg,处理后,下一个将从邮箱中提取。@AleksandarStojadinovic,请稍候。缓冲区没有正确清空。