gpt4 book ai didi

java - 在 Java 5 中实现 ListeningExecutorService

转载 作者:行者123 更新时间:2023-12-03 01:42:59 25 4
gpt4 key购买 nike

在 Java 5 中,ExecutorService 接口(interface)声明方法:

<T> List<Future<T>> invokeAll(Collection<Callable<T>> tasks)
throws InterruptedException;

而 Guava 11.0.2 用 Ja​​va 6 编写,但据称与 Java 5 兼容,在 ListeningExecutorService 中将其重写为:

 <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
throws InterruptedException;

如果我想实现自己的ListeningExecutorService,我需要实现这两个方法,但我也无法让两个方法具有相同的删除功能,所以这有点麻烦22.

有什么办法可以解决这个问题吗?更具体地说,有没有办法在 Java 5 中实现 ListeningExecutorService

作为任何 Guava 人员的旁注——Guava 是否真的有必要重新声明此方法,因为它已经从 ExecutorService 继承了?

最佳答案

原始方法签名已被报告为错误并已在 JDK 6 中修复: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6267833

引用解决消息:

  • is binary compatible.
  • is source compatible for users of an ExecutorService
  • requires minor source code changes for the small set of developers who have implemented ExecutorService without inheriting the default implementations in AbstractExecutorService. The set of affected developers are developers creating sophisticated thread pool applications, putting them into the "concurrency rocket scientist" category. They will generally appreciate this change. The possible compiler error is trivial to fix in the source code.

关于java - 在 Java 5 中实现 ListeningExecutorService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10237259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com