Skip to content

Commit

Permalink
Netty客户端连接释放
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwen5 committed Jan 26, 2015
1 parent 0caf53b commit 43d62fb
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ public class NettyClient extends AbstractClient {
private static final ChannelFactory channelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientBoss", true)),
Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientWorker", true)),
Constants.DEFAULT_IO_THREADS);

static {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
if (logger.isInfoEnabled()) {
logger.info("Run shutdown hook now.");
}

try {
channelFactory.releaseExternalResources();
} catch (Throwable t) {
logger.warn(t.getMessage());
}
}
}, "DubboShutdownHook-NettyClient"));
}

private ClientBootstrap bootstrap;

private volatile Channel channel; // volatile, please copy reference to use
Expand Down Expand Up @@ -147,12 +164,11 @@ protected void doDisConnect() throws Throwable {

@Override
protected void doClose() throws Throwable {
// modified by lishen
try {
/*try {
bootstrap.releaseExternalResources();
} catch (Throwable t) {
logger.warn(t.getMessage());
}
}*/
}

@Override
Expand Down

0 comments on commit 43d62fb

Please sign in to comment.