Questions about asynchronous write operations

Nicholas Clare nickclare at gmail.com
Fri Apr 17 14:30:36 EDT 2009


Hi Utkarsh,

I'm not totally sure about the first question, but I believe that they
are written properly. The second question I do know, because I was
reading the code involved just a little while ago. In the
DefaultChannelListener class, it checks whether the task represented
by the future is done when you add it, and if so, it is called. So the
answer is yes, your listener will be called no matter if it's added
before or after the write finishes

Hope this helps,
Nick

On Fri, Apr 17, 2009 at 6:12 PM, Utkarsh Srivastava <utkarsh at gmail.com> wrote:
> Hi,
>
> I had 2 questions about asynchronous write operations to channels
>
> 1. If I do a sequence of 2 writes to a channel, e.g.,
>
> /*Channel channel;*/
>
> channel.write(obj1);
> channel.write(obj2);
>
> Since the write operations are asynchronous, will the writing of obj1
> and obj2 be properly serialized, or can this result in garbage on the
> wire?
>
>
> 2. The write operation returns a ChannelFuture to which I can add a
> listener for completion of the write. But it seems like there is a
> race condition here. What if the write finishes before I can add a
> listener. Will my listener still be called?
>
> ChannelFuture future = channel.write(obj);
> //write completes
> future.addListener(listener);
>
> //Will the listener be called?
>
> Thanks for the help,
> Utkarsh
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>



More information about the netty-users mailing list