How to define one thread for multiple connections?

hadassa koen hadassa.koen at gmail.com
Thu Nov 25 10:06:46 EST 2010


You're right! I can limit the number of thread to one using  the second
constructor and sending 1 to workerCount.
*NioServerSocketChannelFactory*<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,
int)>(Executor<http://java.sun.com/javase/6/docs/api/java/util/concurrent/Executor.html?is-external=true>
bossExecutor,
Executor<http://java.sun.com/javase/6/docs/api/java/util/concurrent/Executor.html?is-external=true>
workerExecutor,
int workerCount)

(I can also use the Executors.newSingleThreadExecutor() only if workerCount
equals 1, but as you say it's not necessary)

Thanks!

On Thu, Nov 25, 2010 at 12:21 PM, Christian Migowski
<chrismfwrd at gmail.com>wrote:

> 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
> >
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20101125/e1d6a980/attachment-0001.html 


More information about the netty-users mailing list