Netty usage in AS5 (shutdown hangs)

이희승 (Trustin Lee) trustin at gmail.com
Thu Sep 3 22:44:25 EDT 2009


On Wed, 2 Sep 2009 09:46:59 +0900 (KST)
Bob McWhirter <bmcwhirt at redhat.com> wrote:
> 
> On Sep 1, 2009, at 7:57 PM, _댄ъŠ_ (Trustin Lee) wrote:
> > If a ChannelFactory is shared or there are any open connections
> > left, you must not call releaseExternalResources() as it will
> > result in resource leak, infinite loop, and so on.
> 
> Okay, in that case, instead of making the user of ChannelFactory do  
> reference-counting to determine if it's okay to shutdown, can we add
> a stop() method to it?  This way, when it's undeployed by the MC,
> it'll be automatically stopped.
> 
> Otherwise, it seems like it'd be hard to correctly use/shutdown the  
> ChannelFactory in netty.jar's own jboss-beans.xml, particularly if  
> multiple unrelated POJOs are using it to set up unrelated servers.
> 
> Or should I create and manage my ChannelFactories on a per-server
> basis?

I think only one factory is enough for more than one servers.

Actually, Netty does a sort of reference counting.

The resources acquired by ChannelFactories (e.g. Selector) are released
automatically if there is no open channel after about a second.
Therefore, closing all open connections are just enough and Netty will
release other internal resources automatically.  However, there is any
open connection, Netty refuses to shut down.

The problem is that Netty cannot shut down the Executors which was
specified in the ChannelFactory constructor as it is an 'external'
resource which might be shared.  Netty can't do reference counting on
external resources as you know.

Calling releaseExternalResources() simply means shutting down the
Executors, and therefore you don't need to call
releaseExternalResources() if you shut down the executor by yourself
somewhere else.  However, you still need to make sure to close all open
channels (both server channels and accepted channels) before shutting
down.

Things could be much simpler if Netty used ThreadFactory, but I'm not
sure it's a good idea.  I'd love to listen to any good idea for smoother
shut down procedure.

Thanks for feed back, and will look forward to more ;)

-- 
Trustin Lee, http://gleamynode.net/



More information about the netty-users mailing list