[英]Does Netty violate the contract of Future.cancel(…) method?
According the contract from method java.util.concurrent.Future#cancel
: 根据方法
java.util.concurrent.Future#cancel
的合同:
After this method returns, subsequent calls to isDone will always return true.
此方法返回后,对isDone的后续调用将始终返回true。
Netty's Future interface extends it: Netty的Future界面扩展了它:
public interface Future<V> extends java.util.concurrent.Future<V>
So Netty should follow the contract. 所以Netty应该遵守合同。 But in fact Netty does not.
但实际上Netty没有。 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 我已经在github上创建了一个问题: 问题
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. 但我仍然想在stackoverflow中讨论这个问题,因为我认为这是
Future
接口的cancel
和isDone
方法的一个非常基本的设计决策。
There are also some related topics: 还有一些相关的主题:
Future cancel method documentation 未来的取消方法文档
Whether method cancel() in java.util.concurrent.Future shoud be blocking? java.util.concurrent.Future中的方法cancel()是否应该阻塞?
By the way, I am a fan of Netty :) 顺便说一句,我是Netty的粉丝:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.