make sure to call releaseExternalResources on another thread to make sure its not called from a netty IO handler

This commit is contained in:
kimchy 2011-02-01 22:16:09 +02:00
parent 237e936884
commit 8587f16119
1 changed files with 32 additions and 2 deletions

View File

@ -59,7 +59,9 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@ -314,7 +316,21 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
}
if (serverBootstrap != null) {
final CountDownLatch latch = new CountDownLatch(1);
threadPool.cached().execute(new Runnable() {
@Override public void run() {
try {
serverBootstrap.releaseExternalResources();
} finally {
latch.countDown();
}
}
});
try {
latch.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// ignore
}
serverBootstrap = null;
}
@ -325,7 +341,21 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
}
if (clientBootstrap != null) {
final CountDownLatch latch = new CountDownLatch(1);
threadPool.cached().execute(new Runnable() {
@Override public void run() {
try {
clientBootstrap.releaseExternalResources();
} finally {
latch.countDown();
}
}
});
try {
latch.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// ignore
}
clientBootstrap = null;
}
}