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

  • 相关阅读:
    存储过程访问外部服务器
    MVC4 code first 增加属性,对应自动修改列的方法笔记
    摘抄
    一条命令使win7可以直接运行.net3.5程序
    工作心得
    删除一个不存在的东西可以抛出异常吗
    洛谷P3379 【模板】最近公共祖先(LCA)
    洛谷P1967 货车运输
    洛谷P1653 猴子
    洛谷P2278 [HNOI2003]操作系统
  • 原文地址:https://www.cnblogs.com/cdfive2018/p/9710801.html
Copyright © 2011-2022 走看看