Memory visibility in handlers

"Trustin Lee (이희승)" trustin at gmail.com
Mon Mar 8 05:49:58 EST 2010


Hi Greg,

Yes, they are protected by the happens-before contract as defined in
Java memory model.

However, if you access the fields or call the handler methods directly
from other threads than I/O handler threads, you might need synchronization.

Also, unless ExecutionHandler is in the pipeline, the same I/O thread
will call the handler until the end of its life (i.e. disconnection).

If ExecutionHandler is put into the pipeline, more than one thread can
handle the same connection.  Without
OrderedMemoryAwareThreadPoolExecutor (OMATPE), you need explicit
synchronization.  With OMATPE, you don't need explicit synchronization.
 For more information, please refer to the Javadoc of ExecutionHandler
and OMATPE.

HTH,
Trustin

gjwiley wrote:
> Good morning-
> 
> I have noticed that in many of Netty's provided handlers, there is
> no explicit synchronization of member fields. However, if multi-thread
> executors are used to bootstrap a channel, my understanding is that an
> arbitrary thread will be used for each run of the pipeline.
> 
> So, can I assume that synchronization sufficient for change visibility
> occurs within the framework itself? i.e. can I safely assume that
> even without explicit synchronization in a handler method, changes I
> make to handler instance fields will always be visible on subsequent
> runs of the pipeline?
> 
> TIA,
> 
>   -=greg
> 
> 

-- 
what we call human nature in actuality is human habit
http://gleamynode.net/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100308/8a0d5c15/attachment.bin 


More information about the netty-users mailing list