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

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

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();

    private void isDoneTest() {
        boolean isDone = defaultPromise.isDone();

The console should print:


But in fact it print:


The following methods also violate the contract:


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