ExecutorCompletionservice

ExecutorCompletionservice

我已经根据实现了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


似乎完成服务从我的可映射未来中创建了自己的未来(QueueFuture)。

是否有人用ExecutorCompletionService实现了PriorityExecutor?
如果需要,我是否需要扩展ExecutorCompletionService?

最佳答案

我看不到使用内置impl做到这一点的任何方法。但是,ExecutorCompletionService是相当简单的代码,并且是GPL,因此您可以将其复制以供自己使用,然后进行修改以处理自定义的Future。

关于java - 具有ExecutorCompletionService的PriorityExecutor,可以吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27862182/

10-11 22:32