Problem shutdown a Netty server

Patrizio Munzi patrizio.munzi at eris4.com
Wed Mar 4 09:14:33 EST 2009


Hi everybody,
I'm trying to perform a graceful shutdown of a server.
Following the advices in the JavaDoc I'm using the code here below:

---------------------------------------------------------
public final void shutdown() {
    channel.disconnect().awaitUninterruptibly();
    channel.close().awaitUninterruptibly();
    channel.unbind().awaitUninterruptibly();
    try {
        workerExecutor.shutdownNow();
        workerExecutor.awaitTermination(3600, TimeUnit.SECONDS);
        bossExecutor.shutdownNow();
        bossExecutor.awaitTermination(3600, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        // ignore
    }
}
----------------------------------------------------------

where:
- channel = serverBootstrap.bind(new InetSocketAddress(port))
- workerExecutor is the NioServerSocketChannelFactory worker 
ExecutorService reference.
- boosExecutor is the NioServerSocketChannelFactory boss ExecutorService 
reference.

Now, the previous snippet works correctly if I disconnect my client from 
the server before calling it, but it doesn't work if I call it without 
disconnecting my client.
In particular shutdown method execution hangs forever waiting for the 
worker thread termination: workerExecutor.awaitTermination(3600, 
TimeUnit.SECONDS);

Looking a the worker thread object it looks locked on the still 
connected channel.

Is there a way to make it work?
Is there a way to graceful shutdown a server without first disconnecting 
its clients??

Hope in your help!
;-)

Thanks.

-- 

*Patrizio Munzi*
Product Specialist
Viale Bruno Buozzi, 19 - 00197 Roma (Italy)
tel: +39 06 4543 3540
fax: +39 06 4543 3587
mobile: +39 393 7195 164
mail: patrizio.munzi at eris4.com <mailto:patrizio.munzi at eris4.com>
web: http://www.eris4.com <http://www.eris4.com/>
skype: eris4_munzi <skype:eris4_munzi?add>




More information about the netty-users mailing list