java - 使用kryo序列化注册类的含义

标签 java apache-spark serialization kryo

我不明白为 kryo 序列化注册一个类意味着什么。 提供一些背景link这里说的是

Kryo does not support all Serializable types and requires you to register the classes you’ll use in the program in advance for best performance.

我又不明白注册类是什么意思?从应用相同的逻辑来序列化所有类型的对象的意义上来说,序列化代码不是静态的吗?那么提前提及将要序列化的类对以后有什么帮助呢?

谢谢!

最佳答案

Kyro docs提到提前注册不是必需的,但可以提高性能,因为第一次遇到类时不需要序列化类的名称;可以使用注册期间生成的 来代替,这也会导致使用更少的字节。

摘录:

When Kryo writes out an instance of an object, first it may need to write out something that identifies the object's class. By default, the fully qualified class name is written, then the bytes for the object. Subsequent appearances of that object type within the same object graph are written using a variable length int. Writing the class name is somewhat inefficient, so classes can be registered beforehand:

关于java - 使用kryo序列化注册类的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44633410/

相关文章:

java - 在不知道其扩展名的情况下确定文档是 Java 应用程序中的 DOC 还是 DOCX

java - PDF 中的文本以不同方式吐出

python - JPype 和 JayDeBeAPI 返回 jpype._jclass.java.lang.Long

java - 集合中包含可序列化的非原始对象的对象不能设置为 ActiveMQ ObjectMessage

serialization - 为什么锁在Java中是可序列化的?

用于与 IoT 设备通信的 Java TCP 服务器

java - Spring Hibernate 中的多个数据库

java - Spark : . saveAsTextFile 丢失 Java 对象的继承字段

apache-spark - Yarn Heap 使用量随时间增长

c# - Jquery/C# 进行 webService 调用错误 : cannot be serialized because it does not have a parameterless constructor