Made sure NioWorker.taskQueue doesn't contain the same WriteTask
This commit is contained in:
parent
5f1ecc9022
commit
9f5468f7a7
@ -27,6 +27,7 @@ import java.net.SocketAddress;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.jboss.netty.channel.AbstractChannel;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
@ -49,6 +50,7 @@ abstract class NioSocketChannel extends AbstractChannel
|
||||
final SocketChannel socket;
|
||||
private final NioSocketChannelConfig config;
|
||||
|
||||
final AtomicBoolean writeTaskInTaskQueue = new AtomicBoolean();
|
||||
final Runnable writeTask = new WriteTask();
|
||||
final Queue<MessageEvent> writeBuffer =
|
||||
new ConcurrentLinkedQueue<MessageEvent>();
|
||||
@ -119,6 +121,7 @@ abstract class NioSocketChannel extends AbstractChannel
|
||||
}
|
||||
|
||||
public void run() {
|
||||
writeTaskInTaskQueue.set(false);
|
||||
NioWorker.write(NioSocketChannel.this, false);
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,9 @@ class NioWorker implements Runnable {
|
||||
if (mightNeedWakeup) {
|
||||
NioWorker worker = channel.getWorker();
|
||||
if (worker != null && Thread.currentThread() != worker.thread) {
|
||||
worker.taskQueue.offer(channel.writeTask);
|
||||
if (channel.writeTaskInTaskQueue.compareAndSet(false, true)) {
|
||||
worker.taskQueue.offer(channel.writeTask);
|
||||
}
|
||||
if (worker.wakenUp.compareAndSet(false, true)) {
|
||||
worker.selector.wakeup();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user