"Long running" handlers

Virat Gohil virat.gohil at gmail.com
Fri Mar 5 06:29:34 EST 2010


On Fri, Mar 5, 2010 at 10:42 AM, infectedrhytms <infectedrhythms at hotmail.com
> wrote:

>
>        private static final ChannelHandler stringDecoder = new
> StringDecoder();
>        private static final ChannelHandler stringEncoder = new
> StringEncoder();
>        //private static final ChannelHandler isoHandler = new MyHandler();
>
>        public ChannelPipeline getPipeline() throws Exception {
>
>                ChannelPipeline pipeline = Channels.pipeline();
>
>
>                pipeline.addLast("frameDecoder", new
> LengthFieldBasedFrameDecoder(1024, 0,
> 2, 0, 2));
>                pipeline.addLast("decoder", stringDecoder);
>                pipeline.addLast("frameEncoder", new
> LengthFieldPrepender(2));
>                pipeline.addLast("encoder", stringEncoder);
>
>                pipeline.addLast("handler", new MyHandler()); // Calls JDBC
> stored
> procedure, business logic.
>
>                return pipeline;
>        }
>
> MyHandler does the logic and the stored procedure call. This doesn't take
> up
> any CPU time since the handler is waiting on the database to finish, but it
> shouldn't stall/queue other incoming requests.
>
>
>
> --
> View this message in context:
> http://n2.nabble.com/Long-running-handlers-tp4677280p4679153.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>



Hi,

Putting a threadpool (for e.g. OrderedMemoryAwareThreadpoolExecutor) just
before the final handler is a good idea that will unblock the i/o threads.

Remember to share the instance of the Executors across all channels
otherwise you will end up creating a lot of unnecessary threads.

E.g.

public class NioPipelineFactory implements ChannelPipelineFactory {
    private OrderedMemoryAwareThreadPoolExecutor eventExecutors;


    public NioPipelineFactory(OrderedMemoryAwareThreadPoolExecutor
eventExecutors )
    {
        this.eventExecutors=eventExecutors;
    }
    public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = Channels.pipeline();
        pipeline.addLast("frameDecoder", new
LengthFieldBasedFrameDecoder(1024, 0,

>  2, 0, 2));
>      pipeline.addLast("decoder", stringDecoder);
>      pipeline.addLast("frameEncoder", new LengthFieldPrepender(2));
>      pipeline.addLast("encoder", stringEncoder);
>
        pipeline.addLast("Ordered", new ExecutionHandler(eventExecutors));

>      pipeline.addLast("handler", new MyHandler()); // Calls JDBC stored
> procedure, business logic.
>      return pipeline;


HTH,

Thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20100305/f665ddb9/attachment.html 


More information about the netty-users mailing list