我已经实现了一个PriorityExecutor http://funofprograming.blogspot.co.il/2013/11/priorityexecutorservice-for-java.html 和 Specify task order execution in Java
但是,我想使用ExecutorCompletionService
并将其PriorityExecutor
但是我得到以下的执行:
Caused by: java.lang.ClassCastException: java.util.concurrent.ExecutorCompletionService$QueueingFuture cannot be cast to java.lang.Comparable
at java.util.concurrent.PriorityBlockingQueue.siftUpComparable(PriorityBlockingQueue.java:347)
at java.util.concurrent.PriorityBlockingQueue.offer(PriorityBlockingQueue.java:479)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1364)
at java.util.concurrent.ExecutorCompletionService.submit(ExecutorCompletionService.java:188)
at com.ibm.modmt.impl.sommosAlg.meta.PoolStrategy.multiSubmit(PoolStrategy.java:160)
at com.ibm.modmt.impl.sommosAlg.meta.MultiSOMMOSTask.multiSubmit(MultiSOMMOSTask.java:157)
at com.ibm.modmt.impl.sommosAlg.meta.MultiSOMMOSTask.call(MultiSOMMOSTask.java:85)
at com.ibm.modmt.impl.sommosAlg.meta.MultiSOMMOSTask.call(MultiSOMMOSTask.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
... 1 more
似乎完成服务从我的Comaprable Future中创建了自己的Future(QueueFuture
)。
任何人都使用ExecutorCompletionService实现了PriorityExecutor? 如果是这样,我是否需要扩展ExecutorCompletionService?
答案 0 :(得分:2)
我没有看到任何使用内置impl的方法。但是,ExecutorCompletionService是相当简单的代码并且是GPL,因此您可以将其复制以供自己使用并修改它以处理您的自定义Future。