|
storm NotSerializableException统一解决方法:
不能在构造方法中初始化OutputStreamWriter(类似的对象),因为storm先初始化supervisor中的bolt对象,然后发送给worker,在调用prepare()方法
解决的办法就是,从supervisor发送到bolt这一步并不是初始化OutputStreamWriter类,可以先声明相关的对象,然后等发送到 worker了以后,在bolt的prepare()里进行实例化,就可以避免此问题。下面是google来的一段话:
Thesupervisor instantiates the bolts, sends them to the workers, and then callsprepare() on all of them. Therefore, anything that isn't serializable that isinstantiated before prepare() causes this process to fail