[#723] Use ExecutorServer.shutdown() in ExecutorHandler when terminate it. This way not tasks are lost
This commit is contained in:
parent
8e3ec00e33
commit
5ec179c33c
@ -17,9 +17,9 @@ package org.jboss.netty.handler.execution;
|
|||||||
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||||
import org.jboss.netty.util.internal.ExecutorUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A special {@link Executor} which allows to chain a series of
|
* A special {@link Executor} which allows to chain a series of
|
||||||
@ -72,7 +72,12 @@ public class ChainedExecutor implements Executor, ExternalResourceReleasable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void releaseExternalResources() {
|
public void releaseExternalResources() {
|
||||||
ExecutorUtil.terminate(cur, next);
|
if (cur instanceof ExecutorService) {
|
||||||
|
((ExecutorService) cur).shutdown();
|
||||||
|
}
|
||||||
|
if (next instanceof ExecutorService) {
|
||||||
|
((ExecutorService) next).shutdown();
|
||||||
|
}
|
||||||
releaseExternal(cur);
|
releaseExternal(cur);
|
||||||
releaseExternal(next);
|
releaseExternal(next);
|
||||||
}
|
}
|
||||||
|
@ -64,13 +64,7 @@ public abstract class ChannelEventRunnable implements Runnable, EstimatableObjec
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void run() {
|
public final void run() {
|
||||||
try {
|
doRun();
|
||||||
PARENT.set(executor);
|
|
||||||
doRun();
|
|
||||||
} finally {
|
|
||||||
PARENT.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void doRun();
|
protected abstract void doRun();
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package org.jboss.netty.handler.execution;
|
package org.jboss.netty.handler.execution;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import org.jboss.netty.bootstrap.ServerBootstrap;
|
import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||||
import org.jboss.netty.channel.Channel;
|
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.ChannelUpstreamHandler;
|
||||||
import org.jboss.netty.channel.Channels;
|
import org.jboss.netty.channel.Channels;
|
||||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||||
import org.jboss.netty.util.internal.ExecutorUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forwards an upstream {@link ChannelEvent} to an {@link Executor}.
|
* Forwards an upstream {@link ChannelEvent} to an {@link Executor}.
|
||||||
@ -160,7 +160,9 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre
|
|||||||
*/
|
*/
|
||||||
public void releaseExternalResources() {
|
public void releaseExternalResources() {
|
||||||
Executor executor = getExecutor();
|
Executor executor = getExecutor();
|
||||||
ExecutorUtil.terminate(ChannelEventRunnable.PARENT, executor);
|
if (executor instanceof ExecutorService) {
|
||||||
|
((ExecutorService) executor).shutdown();
|
||||||
|
}
|
||||||
if (executor instanceof ExternalResourceReleasable) {
|
if (executor instanceof ExternalResourceReleasable) {
|
||||||
((ExternalResourceReleasable) executor).releaseExternalResources();
|
((ExternalResourceReleasable) executor).releaseExternalResources();
|
||||||
}
|
}
|
||||||
|
@ -109,19 +109,13 @@ public class ExecutionHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendUpstream(ChannelEvent e) {
|
public void sendUpstream(ChannelEvent e) {
|
||||||
try {
|
handler.releaseExternalResources();
|
||||||
handler.releaseExternalResources();
|
latch.countDown();
|
||||||
} catch (IllegalStateException ex) {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendDownstream(ChannelEvent e) {
|
public void sendDownstream(ChannelEvent e) {
|
||||||
try {
|
handler.releaseExternalResources();
|
||||||
handler.releaseExternalResources();
|
latch.countDown();
|
||||||
} catch (IllegalStateException ex) {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getAttachment() {
|
public Object getAttachment() {
|
||||||
|
Loading…
Reference in New Issue
Block a user