How to define one thread for multiple connections?

Christian Migowski chrismfwrd at gmail.com
Thu Nov 25 05:21:16 EST 2010


I haven't used Executors.newSingleThreadExecutor() in my own code, why
don't you try

                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));

as most of the Netty examples do? That definitively doesn't create a
thread per connection and also handles lot of concurrent connections
just fine.
I think you should read the javadoc, it is all explained very nicely
in there [1].

hth,
christian!

[1] http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/socket/nio/NioServerSocketChannelFactory.html#NioServerSocketChannelFactory(java.util.concurrent.Executor,
java.util.concurrent.Executor)




On Thu, Nov 25, 2010 at 9:46 AM, hada <hadassa.koen at gmail.com> wrote:
>
> OK. I will precise my question:
> if you define the NioServerSocketChannelFactory as
> new
> NioServerSocketChannelFactory(Executors.newSingleThreadExecutor(),Executors.newSingleThreadExecutor()),
> only one workerThread will be created.
> Say that the client sends "Hello, I'm client" message and the server
> responds with a "hello, I'm server" and then the client re-send "Hello, i'm
> client" etc....
> for the first client this message exchange happens, but no for a second
> client. This is because only a single thread is allowed for workerThread in
> NioServerSocketChannelFactory.
> Only when the first client will be disconnected, the second one will
> "receives" the thread, and then the message exchange will start.
> (however, in the netstat i see that the connection is established for the 2
> clients, although only the first client is 'active')
>
> What I want is that only one thread will be manage the exchange message for
> many connections!
>
>
>
> --
> View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/How-to-define-one-thread-for-multiple-connections-tp5773292p5773426.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
>


More information about the netty-users mailing list