每个连接有Netty多线程 [英] Netty multi threading per connection

查看:163
本文介绍了每个连接有Netty多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手.我想开发一种服务器,该服务器旨在接收可能来自少数客户端的请求(例如Max的2个客户端).但是每个客户端将不断向服务器发送许多请求.服务器必须处理此类请求并响应客户端.因此,在此我假设即使配置了多个工作线程,也可能没有用,因为只有2个活动连接.工作线程再次阻塞,直到它处理并响应客户端.因此,请让我知道如何处理此类问题. 如果我在工作线程中使用threadpoolexecutor以多线程方式处理两个客户端请求,效率高吗?或者,如果它可以通过netty框架实现,请让我知道该怎么做? 预先感谢...

I am new to netty. I would like to develop a server which aims at receiving requests from possibly few(say Max is of 2) clients. But each client will be sending many requests to server continuously. Server has to process such requests and respond to client. So, here I assume that even though if I configure multiple worker threds,it may not be useful as there are only 2 active connections. Worker thread again block till it process and respond to client. So, please let me know how to handle these type of problems. If I use threadpoolexecutor in worker thread to process both clients requests in multi threaded manner, will it be efficient? Or if it cane achieved through netty framework, plz let me know how to do this? Thanks in advance...

推荐答案

只需将带有特殊EventExecutorGroup的ChannelHandler添加到ChannelPipeline.例如UnorderedThreadPoolEventExecutor( src ).

just add a ChannelHandler with a special EventExecutorGroup to the ChannelPipeline. For example UnorderedThreadPoolEventExecutor (src).

类似这样的东西.

UnorderedThreadPoolEventExecutor executorGroup = ...;
pipeline.addLast(executorGroup, new MyChannelHandler());

这篇关于每个连接有Netty多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆