gpt4 book ai didi

使用 Kryo 序列化对象时出现 java.lang.StackOverflowError

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:28:46 25 4
gpt4 key购买 nike

我有一个从服务器发送到客户端的类图对象,其中包含具有 adjacencyListsnodes

我有类似的东西:

Clearing c1 = new Clearing(1, 134, 151);
Clearing c6 = new Clearing(6, 250, 88);

c1.adjacentByPath.add(new Path(1, c6));
c6.adjacentByPath.add(new Path(1, c1));

每次我发送包含这些清算的对象时,我都会收到以下错误:

Exception in thread "Server" java.lang.StackOverflowError
at com.esotericsoftware.kryo.Kryo.getRegistration(Kryo.java:448)
at com.esotericsoftware.kryo.util.DefaultClassResolver.writeClass(DefaultClassResolver.java:79)
......

在 Kryonet 中有解决这个问题的方法吗?谢谢

最佳答案

这是迟到的答案,但最近我遇到了这个问题并且能够复制和修复。


每当在 kryo 序列化中使用大对象图时,就会发生这种情况...

Fix :
1) Try to fix this by tail recursion examples here
2) Increase stack size by specifying Xss in vm options

-Xss1m(或根据您的要求增加)按照 Esoteric software documentation which developed Kryo 的建议

非常大的对象图:

Stack size

The serializers Kryo provides use the call stack when serializing nested objects. Kryo does minimize stack calls, but for extremely deep object graphs, a stack overflow can occur. This is a common issue for most serialization libraries, including the built-in Java serialization. The stack size can be increased using -Xss, but note that this is for all threads. Large stack sizes in a JVM with many threads may use a large amount of memory.

针对 apache spark + Kryo 用户的提示:

In case of spark I set SparkConf object spark.executor.extraJavaOptions=... (along with -Xmx -XX options) programmatically or you can also mention that in spark-default.conf

关于使用 Kryo 序列化对象时出现 java.lang.StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28640543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com