How to organize sync messages

Carl Byström cgbystrom at gmail.com
Sat Dec 12 06:42:50 EST 2009


On Thu, Dec 10, 2009 at 6:08 PM, drofa <drofa at yahoo.com> wrote:

>
> I'm new to Netty, and I need some help, Netty is async by nature but right
> now I need to process some client to server requests in synchronous way..
> so
> after call to server I method is blocked until server response arrives or
> failed by timeout.. I would appreciate any code example . Thanks in advance
>
>
You need to make sure you put your handler after an ExecutionHandler. By
doing that, processing will be deferred to worker threads, decoupled from
the main I/O loop.
The main I/O has by default X threads, where X is number of processors. If
you block that, you will block the server's ability to process I/O.
It's recommended to only put CPU-bound code here (such as protocol
encoding/decoding) and defer handlers that do blocking I/O to worker threads
behind an ExecutionHandler.

See http://www.jboss.org/community/wiki/NettyExampleofPingPongusingObjectand
the PongPipelineFactory class. You'll see in the getPipeline() method
how a pipeline executor gets inserted. OrderedMemoryAwareThreadPoolExecutor
is probably what you want.

--
Carl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20091212/ef7d6aa6/attachment.html 


More information about the netty-users mailing list