简体   繁体   中英

Java ExecutorCompletionService How know which task is returned

ExecutorService serv = Executors.newFixedThreadPool(5);
CompletionService<Integer> servive = new ExecutorCompletionService<>(serv);

for (int i = 0; i < 5; i++) {
  servive.submit(new MyTask(i));
}

for (int i = 0; i < 5; i++) {
  Future<Integer> f = null;
  try {
    f = servive.take();
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
  //f.get()
}

I want to know which task or callable was completed in the first result( f.get() )
How do I do that, or what other functions?

好吧,它完全取决于JVM和任务,如何由JVM处理。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM