当前位置:   article > 正文

flink 报错is not serializable. The object probably contains or references non serializable fields.

is not serializable. the object probably contains or references non serializ

今天有同事突然报了这样一个错误,刚开始确实没反应过来,成员变量不可以被序列化。。。。

Exception in thread "main" org.apache.flink.api.common.InvalidProgramException: java.lang.ref.ReferenceQueue$Lock@11fc564b is not serializable. The object probably contains or references non serializable fields.
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:151)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:126)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:126)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:126)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:126)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:126)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:71)
	at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.clean(StreamExecutionEnvironment.java:1821)
	at org.apache.flink.streaming.api.datastream.DataStream.clean(DataStream.java:188)
	at org.apache.flink.streaming.api.datastream.KeyedStream.process(KeyedStream.java:398)
	at org.apache.flink.streaming.api.datastream.KeyedStream.process(KeyedStream.java:374)
	at com.xintujing.flinkdemo.text.UserCount_3.main(UserCount_3.java:53)
Caused by: java.io.NotSerializableException: java.lang.ref.ReferenceQueue$Lock
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at org.apache.flink.util.InstantiationUtil.serializeObject(InstantiationUtil.java:586)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:133)
	... 11 more
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

看到这个错,首先处于懵的状态,无法序列化,什么意思啊?

首先分析问题,他告诉我们某个类无法序列化了,

如果类中的一个成员未实现可序列化接口, 会发生什么情况?关于Java序列化过程的一个简单问题。如果尝试序列化实现可序列化的类的对象,但该对象包含对不可序列化类的引用,则在运行时将引发不可序列化异常 NotSerializableException,

是这样,如果你把一个对象作为另一个对象的成员变量,那么必须这个对象的所有成员变量都是可以被序列化的,如果成员变量不可以被序列化,那么就会报这个错误。所以。不要把不可序列化的东西当作成员变量就可以了啊。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/767779?site
推荐阅读
相关标签
  

闽ICP备14008679号