Hi Eyal,

you should be instantiating it on first access instead, then (preferably)
getting one of the bolts to do so in the prepare method.

Rules of singletons still apply, do your double-check locking to ensure you
don't do it twice.

Doing it in the main method will initialize it on the machine you're using
to run storm jar. When the main method is run it instantiates the bolts,
serializes them, and sends them up. Then they're deserialized and prepare()
is called. Classes outside the members of spouts & bolts don't get
serialized, and you'd probably rather not serialize a ton of data anyways :)

Michael Rose (@Xorlev <https://twitter.com/xorlev>)
Senior Platform Engineer, FullContact <http://www.fullcontact.com/>
[email protected]

On Thu, Dec 4, 2014 at 12:01 PM, Eyal Golan <[email protected]> wrote:

> Hi all,
> I am newbie with Storm and having some issues with static objects in the
> topology.
> In the main class, where I set the topology, I also set a static object.
> It's actually a wrapper for a collection of strings.
> This object needs to he shared between different bolts.
> It's big so I want it to be only one instance.
>
> The problem is that when a bolt tries to get this static instance: example
> - MyMain.Shared... It's null. Although I instantiated it in the main method.
>
> I guess I'm doing something wrong.
>
> Thanks for any assistance.
>
> Eyal
>
> Sent from my Android phone
>

Reply via email to