不确定是否有Ignite提供的java.util.concurrent.CompletionService实现,如Infinispan(org.infinispan.distexec.DistributedExecutionCompletionService),
编辑:
以下是示例代码,如果以分布式模式启动(在三个终端中)
,则无效public void run(boolean isMaster, final String nodeName) throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setGridName(nodeName);
Ignite ignite = Ignition.start(cfg);
if (isMaster) {
CompletionService<String> service = new ExecutorCompletionService<String>(ignite.executorService());
for (int i = 0; i < 10; i++) {
service.submit(new Callable<String>() {
@Override
public String call() throws Exception {
System.out.println("Executing ");
return String.valueOf(new Random().nextInt(10));
}
});
}
for (int i = 0; i < 10; i++) {
Future<String> f = service.take();
System.out.println(f.get());
}
}
System.out.println("Ctrl+D/Ctrl+Z to stop.");
}
第1号航站楼
mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.ignite.Node" -Dexec.classpathScope="test" -Dexec.args="s node-A"
输出
[22:29:59] Topology snapshot [ver=3, servers=3, clients=0, CPUs=4, heap=5.3GB]
Executing
Executing
Executing
Termincal#2
mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.ignite.Node" -Dexec.classpathScope="test" -Dexec.args="s node-B"
输出
[22:29:59] Topology snapshot [ver=3, servers=3, clients=0, CPUs=4, heap=5.3GB]
Executing
Executing
Executing
终端#3:主人
mvn test-compile exec:java -Dexec.classpathScope="test" -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.ignite.Node" -Dexec.args="m node-C"
输出
[22:29:59] Topology snapshot [ver=3, servers=3, clients=0, CPUs=4, heap=5.3GB]
Executing
Executing
6
2
Executing
4
Executing
3
它应该打印6个随机整数,但它永远阻止
这是whole project遵循Node类
中的指令注意:我能够使用&#39; igniteCompute.call&#39;来获得CompletionService的功能。和&#39; igniteCompute.future()。listen(newListener());&#39;,但我不认为这是有效的。请参阅example
答案 0 :(得分:0)
Ignite提供ExecutorService
的实现,因此您可以使用JDK中包含的ExecutorCompletionService
。
CompletionService<Object> service =
new ExecutorCompletionService<>(ignite.executorService());