Home Does Netty violate the contract of Future.cancel(...) method?
Reply: 0

Does Netty violate the contract of Future.cancel(...) method?

user1899
1#
user1899 Published in June 23, 2018, 9:24 pm

According the contract from method java.util.concurrent.Future#cancel :

After this method returns, subsequent calls to isDone will always return true.

Netty's Future interface extends it:

public interface Future<V> extends java.util.concurrent.Future<V>

So Netty should follow the contract. But in fact Netty does not. You can run this sample code:

import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;

public class DefaultPromiseIsDoneTest {

    private final Promise<?> defaultPromise = GlobalEventExecutor.INSTANCE.newPromise();

    public static void main(String args[]) {
        DefaultPromiseIsDoneTest main = new DefaultPromiseIsDoneTest();
        main.isDoneTest();
    }

    private void isDoneTest() {
        defaultPromise.setUncancellable();
        defaultPromise.cancel(false);
        boolean isDone = defaultPromise.isDone();
        System.out.println(isDone);
    }
}

The console should print:

true

But in fact it print:

false

The following methods also violate the contract:

io.netty.channel.group.VoidChannelGroupFuture#isDone
io.netty.channel.VoidChannelPromise#isDone

I already created an issue on github: issue

But I still want to discuss this here in stackoverflow, because I think this is a pretty fundamental design decision for cancel & isDone methods of Future interface.

There are also some related topics:

Future cancel method documentation

Whether method cancel() in java.util.concurrent.Future shoud be blocking?

By the way, I am a fan of Netty :)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.3151 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO