赞
踩
今天有同事突然报了这样一个错误,刚开始确实没反应过来,成员变量不可以被序列化。。。。
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
看到这个错,首先处于懵的状态,无法序列化,什么意思啊?
首先分析问题,他告诉我们某个类无法序列化了,
如果类中的一个成员未实现可序列化接口, 会发生什么情况?关于Java序列化过程的一个简单问题。如果尝试序列化实现可序列化的类的对象,但该对象包含对不可序列化类的引用,则在运行时将引发不可序列化异常 NotSerializableException,
是这样,如果你把一个对象作为另一个对象的成员变量,那么必须这个对象的所有成员变量都是可以被序列化的,如果成员变量不可以被序列化,那么就会报这个错误。所以。不要把不可序列化的东西当作成员变量就可以了啊。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。