blocking when sending lots of data
"이희승 (Trustin Lee)"
trustin at gmail.com
Wed Jul 8 01:44:03 EDT 2009
On 07/07/2009 03:05 AM, mra wrote:
> thanks trustin.
>
> i see that you use java.util.Queue.offer() in ChunkedWriteHandler to
> account for the downstream message, which doesn't block if queue's
> capacity is full. so it seems as though excess netty messages are
> simply dropped (line 98 in 3.1.0.CR1).
Yes, nothing blocks there. It's not dropped actually, but just queue
for later write.
> so could you suggest an implementation that would actually block the
> writer, if more data is being generated via netty than can be handled
> by the underlying o/s's tcp/ip implementation?
You could use a lock to implement blocking operation. For example:
// Blocking write
synchronized (lock) {
while (!ch.isWritable()) {
lock.wait();
}
ch.write(something);
}
// Unblock the wait() call in channelInterestChanged()
synchronized (lock) {
if (evt.getChannel().isWritable()) {
lock.notify();
}
}
I would still recommend you to try event-driven approach I demonstrated
in ChunkedWriteHandler if possible.
HTH,
Trustin
More information about the netty-users
mailing list