ChannelFuture.await() and ChannelFutureListener.operationComplete()
Utkarsh Srivastava
utkarsh at gmail.com
Sat Apr 4 01:18:05 EDT 2009
In Approach 1, the thread that calls the write does not block and can go on
to do the other stuff. The channel is closed by the thread that eventually
finishes the write (one of Netty's IO threads).
In Approach 2, the thread that calls the write blocks until the write
finishes.
Utkarsh
On Fri, Apr 3, 2009 at 8:55 PM, hezjing <hezjing at gmail.com> wrote:
> Hi
> I'm following the Writing a Time Server<http://www.jboss.org/file-access/default/members/netty/freezone/guide/3.1/html_single/index.html#d0e489> chapter
> of Netty 3.1 user's guide.
>
> Here is the code snippet to close the connection after a message is written
> successfully:
>
> ChannelFuture f = ch.write(time);
> f.addListener(new ChannelFutureListener() {
> public void operationComplete(ChannelFuture future) {
> Channel ch = future.getChannel();
> ch.close();
> }
> });
>
>
> I think the above code can also be simplified to the following (?):
>
> ChannelFuture f = ch.write(time);
> f.await();
> ch.close();
>
>
> Am I correct to say that both approaches are identical?
>
>
> --
>
> Hez
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20090403/6765a5fe/attachment.html
More information about the netty-users
mailing list