0

In some of my experiments with Netty the main thread exits before all the I/O threads are complete. I've been using a CountDownLatch to prevent this. Is this the right approach? Is there a standard approach for avoiding this?

4

2 回答 2

0

我会说倒计时锁存器是一个好方法。但我不知道我是否称其为标准。一般来说,关机是一个难题。我工作过的大多数应用程序都使用了一系列不同的方法来关闭它们的各种组件。

于 2013-01-14T15:45:42.207 回答
0

您可以等到您创建的频道关闭。例如:

public static void main(St ring[] args) throws Exception {
    ChannelFactory f = ...;
    try {
        ...
        Channel ch = bootstrap.connect().sync();
        ch.getCloseFuture().sync(); // Wait until the channel is closed.
    } finally {
        f.releaseExternalResources();
    }
}
于 2013-01-18T03:09:56.800 回答