Simultaneous invocation of handlers

Trustin Lee (이희승) trustin at gmail.com
Wed Oct 21 21:35:16 EDT 2009


Hi Dan,

Frederic already gave a good answer, so I'd like to address only one issue.

On Mon, Oct 19, 2009 at 8:29 AM, Dan D <danotsky at gmail.com> wrote:
> Are there any visibility guarantees across invocations of Handlers? E.g. if
> I handle an event in my per-Channel handler and change a member variable of
> the Handler, will that change be visible when the same Handler instance is
> invoked for the next event in a different thread?

Because the next event can be invoked in a different thread than the
previous event even for the same channel, JVM cannot guarantee the
visibility although there seems no issue practically.  I prefer to
declare the member variables as 'volatile' just in case.  I don't
think there will be much overhead even if you have many volatile
fields because there's high chance where they are placed in the same
cache line.

HTH

— Trustin Lee, http://gleamynode.net/



More information about the netty-users mailing list