Fixed issue NETTY-50 (Dead lock in MemoryAwareThreadPoolExecutor)

* Fixed incorrect release condition
This commit is contained in:
Trustin Lee 2008-09-30 00:16:42 +00:00
parent d7c53437e9
commit 50f043fa3e

View File

@ -224,14 +224,8 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
boolean pause = increaseCounter(command); boolean pause = increaseCounter(command);
doExecute(command); doExecute(command);
if (pause) { if (pause) {
for (;;) { //System.out.println("ACQUIRE");
try { semaphore.acquireUninterruptibly();
semaphore.acquire();
break;
} catch (InterruptedException e) {
// Ignore.
}
}
} }
} }
@ -289,6 +283,7 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
} }
} }
//System.out.println("I: " + totalCounter + ", " + increment);
return maxTotalMemorySize != 0 && totalCounter >= maxTotalMemorySize; return maxTotalMemorySize != 0 && totalCounter >= maxTotalMemorySize;
} }
@ -310,14 +305,16 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
int totalCounter = this.totalCounter.addAndGet(-increment); int totalCounter = this.totalCounter.addAndGet(-increment);
if (maxTotalMemorySize == 0 || totalCounter < maxTotalMemorySize) { //System.out.println("D: " + totalCounter + ", " + increment);
if (maxTotalMemorySize != 0 && totalCounter + increment >= maxTotalMemorySize) {
//System.out.println("RELEASE");
semaphore.release(); semaphore.release();
} }
if (task instanceof ChannelEventRunnable) { if (task instanceof ChannelEventRunnable) {
Channel channel = ((ChannelEventRunnable) task).getEvent().getChannel(); Channel channel = ((ChannelEventRunnable) task).getEvent().getChannel();
int channelCounter = getChannelCounter(channel).addAndGet(-increment); int channelCounter = getChannelCounter(channel).addAndGet(-increment);
if ((maxChannelMemorySize == 0 || channelCounter < maxChannelMemorySize) && channel.isOpen()) { if (maxChannelMemorySize != 0 && channelCounter + increment >= maxChannelMemorySize && channel.isOpen()) {
if (!channel.isReadable()) { if (!channel.isReadable()) {
channel.setReadable(true); channel.setReadable(true);
} }