Storm初始化報錯java.io.NotSerializableException

來源:互聯網
上載者:User

最近在做即時資料分析,使用到了twitter開源的storm,在初始化的時候報了一個序列化的錯:

java.lang.RuntimeException: java.io.NotSerializableException: org.joda.time.format.DateTimeFormatter

報錯資訊很明顯,因為DateTimeFormatter不支援序列化。但是我只是在bolt裡使用到了這個時間類,不至於在初始化的時候就報錯啊?

上網搜了下原因,是因為storm工作機制的問題。在你啟動一個topology以後,supervisor會初始化這個bolt,並發送到worker,然後再調用bolt的prepare()方法。OK,從這裡就能看出來發送到bolt這一步涉及到了序列化,因此會報錯。

解決的辦法就是,從supervisor發送到bolt這一步並不是初始化DateTimeFormatter類,可以先聲明相關的對象,然後等發送到worker了以後,在bolt的prepare()裡進行執行個體化,就可以避免此問題。下面是google來的一段話:

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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.