在Java 5中实现ListeningExecutorService [英] Implementing ListeningExecutorService in Java 5

查看:112
本文介绍了在Java 5中实现ListeningExecutorService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java 5中,ExecutorService接口声明该方法:

In Java 5, the ExecutorService interface declares the method:

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

以Java 6编写但应该与Java 5兼容的Guava 11.0.2则在ListeningExecutorService中将其覆盖为:

whereas Guava 11.0.2, written in Java 6 but supposedly compatible with Java 5, overrides it in ListeningExecutorService as:

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

如果我想实现自己的ListeningExecutorService,则需要实现这两种方法,但是我也无法同时擦除两种方法,因此有点像Catch 22.

If I want to implement my own ListeningExecutorService, I would need to implement both of these methods, but I am also not able to have two methods the same erasure, so it's a bit of a Catch 22.

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

Is there any way around this problem? More specifically, is there any way to implement a ListeningExecutorService in Java 5?

作为番石榴所有人的补充说明-番石榴实际上是否有必要重新声明此方法,因为它已经从ExecutorService继承了?

As a side note to any Guava folks--is it actually necessary for Guava to re-declare this method since it's already inherited from ExecutorService?

推荐答案

我们完成这项工作的方式是在bootclasspath中覆盖JDK的ExecutorService接口.您可以在项目的编译过程中执行类似的操作.查看设置的最简单方法可能是更改已将其从版本12中删除(因为该版本将需要JDK6).

The way that we made this work was to override the JDK's ExecutorService interface in our bootclasspath. You could do something similar during your project's compilation. The easiest way to see our setup is probably the change that removed it for release 12 (since that release will require JDK6).

这篇关于在Java 5中实现ListeningExecutorService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆