[#723] Use ExecutorServer.shutdown() in ExecutorHandler when terminate it. This way not tasks are lost

This commit is contained in:
Norman Maurer 2012-11-17 19:47:06 +01:00
parent 8e3ec00e33
commit 5ec179c33c
4 changed files with 16 additions and 21 deletions

View File

@ -17,9 +17,9 @@ package org.jboss.netty.handler.execution;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import org.jboss.netty.util.ExternalResourceReleasable;
import org.jboss.netty.util.internal.ExecutorUtil;
/**
* A special {@link Executor} which allows to chain a series of
@ -72,7 +72,12 @@ public class ChainedExecutor implements Executor, ExternalResourceReleasable {
}
public void releaseExternalResources() {
ExecutorUtil.terminate(cur, next);
if (cur instanceof ExecutorService) {
((ExecutorService) cur).shutdown();
}
if (next instanceof ExecutorService) {
((ExecutorService) next).shutdown();
}
releaseExternal(cur);
releaseExternal(next);
}

View File

@ -64,13 +64,7 @@ public abstract class ChannelEventRunnable implements Runnable, EstimatableObjec
}
public final void run() {
try {
PARENT.set(executor);
doRun();
} finally {
PARENT.remove();
}
doRun();
}
protected abstract void doRun();

View File

@ -16,6 +16,7 @@
package org.jboss.netty.handler.execution;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel;
@ -31,7 +32,6 @@ import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.util.ExternalResourceReleasable;
import org.jboss.netty.util.internal.ExecutorUtil;
/**
* Forwards an upstream {@link ChannelEvent} to an {@link Executor}.
@ -160,7 +160,9 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre
*/
public void releaseExternalResources() {
Executor executor = getExecutor();
ExecutorUtil.terminate(ChannelEventRunnable.PARENT, executor);
if (executor instanceof ExecutorService) {
((ExecutorService) executor).shutdown();
}
if (executor instanceof ExternalResourceReleasable) {
((ExternalResourceReleasable) executor).releaseExternalResources();
}

View File

@ -109,19 +109,13 @@ public class ExecutionHandlerTest {
}
public void sendUpstream(ChannelEvent e) {
try {
handler.releaseExternalResources();
} catch (IllegalStateException ex) {
latch.countDown();
}
handler.releaseExternalResources();
latch.countDown();
}
public void sendDownstream(ChannelEvent e) {
try {
handler.releaseExternalResources();
} catch (IllegalStateException ex) {
latch.countDown();
}
handler.releaseExternalResources();
latch.countDown();
}
public Object getAttachment() {