Fixed a problem where NioWorker.writeNow() doesn't work when it's called recursively

* Added a boolean thread local variable to check if writeNow() has been called by itself
This commit is contained in:
Trustin Lee 2009-02-26 10:32:33 +00:00
parent 1ff58978a2
commit 903c530ae0

View File

@ -51,6 +51,7 @@ import org.jboss.netty.channel.ReceiveBufferSizePredictor;
import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.jboss.netty.util.LinkedTransferQueue;
import org.jboss.netty.util.ThreadLocalBoolean;
import org.jboss.netty.util.ThreadRenamingRunnable;
/**
@ -68,6 +69,8 @@ class NioWorker implements Runnable {
private static final int CONSTRAINT_LEVEL = NioProviderMetadata.CONSTRAINT_LEVEL;
private static final ThreadLocalBoolean writing = new ThreadLocalBoolean();
private final int bossId;
private final int id;
private final Executor executor;
@ -327,7 +330,17 @@ class NioWorker implements Runnable {
return;
}
writeNow(channel, channel.getConfig().getWriteSpinCount());
if (writing.get()) {
scheduleWriteIfNecessary(channel);
} else {
writing.set(Boolean.TRUE);
try {
writeNow(channel, channel.getConfig().getWriteSpinCount());
} finally {
writing.set(Boolean.FALSE);
}
}
}
private static boolean scheduleWriteIfNecessary(NioSocketChannel channel) {