zoukankan      html  css  js  c++  java
  • storm java.io.NotSerializableException

    今天编写一个storm的topology,bolt的逻辑跟之前的类似。

    为了减少重复代码,我建了个抽象基类,存放bolt的公共逻辑,设计了几个abstract方法,不同的逻辑部分由子类实现。

    基类日志定义如下:

    private static final Logger LOG = LoggerFactory.getLogger(AbstractXxxBolt.class);

    Logger是项目封装的,用于ELK的对象,考虑到子类可能用到,我把它的static去掉,AbstractXxxBolt.class改成了getClass();

    本机启动topology报错:storm java.io.NotSerializableException Logger;

    改回static后,启动正常;

    子类中,有引用其它工程的dubbo服务接口,开始写在构造函数中初始化的,

    private XxxService xxxService;
    
    SubClass() {
       super();
       xxxService = XxxUtil.getBean(XxxService.class);
    }

    本机启动topology报错:storm NotSerializableException com.alibaba.dubbo.common.bytecode.proxy0

    解决方法:

    将子类构造函数中的赋值去掉,抽象一个doPrepare()方法,在基类的prepare()方法中调用

    子类实现doPrepare(),在其中xxxService = XxxUtil.getBean(XxxService.class);

    -----------------------------------------------------------------------------------------------------------------------------

    The supervisor instantiates the bolts, sends them to the workers, and then calls prepare() on all of them. Therefore, anything
    that isn't serializable that is instantiated before prepare() causes this process to fail.

    -----------------------------------------------------------------------------------------------------------------------------

    参考:

    https://blog.csdn.net/wanghai__/article/details/8997895

  • 相关阅读:
    [恢]hdu 1412
    [恢]hdu 2212
    [恢]hdu 1407
    [恢]hdu 1228
    [恢]hdu 1337
    [恢]hdu 1014
    [恢]hdu 2200
    定居到博客园了!
    比较GridView,DataList,Repeator ,DetailsView,FormView
    随手记录修改某条记录时,不使用数据库控件而用datareader
  • 原文地址:https://www.cnblogs.com/cdfive2018/p/9710801.html
Copyright © 2011-2022 走看看