Graceful and Forced Shutdown Feature

Trustin Lee (이희승) trustin at gmail.com
Tue Sep 29 04:25:27 EDT 2009


On Fri, Sep 25, 2009 at 10:43 AM, sohguanh <sohguanh at yahoo.com.sg> wrote:
>
> I understand Netty is an NIO framework but it would be nice to enhance it
> with pre-built classes for doing server graceful and forced shutdown.
>
> Graceful shutdown
> I discover the tutorial and common technique is run a forever loop,
> Thread.sleep(x) then check some condition to indicate a shutdown is to be
> executed. This technique means some latency as the main thread will only
> wake up after x seconds to check.
>
> In JDK 1.5 I uses java.util.concurrent.CountDownLatch and the main thread
> execute await() method. This will block until the CountDownLatch count
> reached zero. Then in the server handler thread once the shutdown command is
> received, it will execute countDown() to decrement the count. This approach
> greatly improve the latency the main thread receive shutdown command. Seems
> await() method will wake up and not wait x seconds using the Thread.sleep(x)
> technique.
>
> I hope Netty new release provide some shutdown classes using various
> techniques for graceful shutdown.

I'm not sure you read the user guide, but you will find out how to
shut down a server or a client as quickly as possible there.

> Forced shutdown
> How do Netty server detect JVM dies so it can terminate gracefully? I
> discover java.lang.Runtime.addShutdownHook method and also the
> com.sun.misc.Signals but seem not working for me in a predictable manner.
>
> I hope Netty new release provide some shutdown classes using various
> techniques for forced shutdown.

Considering that Netty can be used in various environments such as
application server, adding a shutdown hook or a similar stuff should
be taken care by user.

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



More information about the netty-users mailing list