A code snippet of netty examples from netty.io seems have bugs -


the code snippet is:

        final channelfuture f = ctx.writeandflush(time);          f.addlistener(new channelfuturelistener() {              public void operationcomplete(channelfuture future) {                 assert f == future;                 ctx.close();             }         });  

what happens if ' final channelfuture f = ctx.writeandflush(time); ' executes fast next addlistener code not start yet. when first line of code completes, thread notifies listeners operation done, @ time, there no listener @ all! after that, new listener added no more notifications received!

code source: http://netty.io/wiki/user-guide-for-5.x.html

the channelfuture retains completion state if listener added after completion, "late" added listener called on addition.

see javadoc channelfuture.addlistener(genericfuturelistener), comment:

if future completed, specified listener notified immediately.

see impl defaultpromise. late listeners (i.e. listeners added once future complete) have own handler (notifylatelistener).


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -