How to use invokeAll() to let all thread pool do their task?

前端 未结 3 1275
失恋的感觉
失恋的感觉 2020-11-29 03:15
    ExecutorService pool=Executors.newFixedThreadPool(7);
        List> future=new ArrayList>();
        List<         


        
3条回答
  •  日久生厌
    2020-11-29 03:23

    invokeAll is a blocking method. It means – JVM won’t proceed to next line until all the threads are completed. So I think there is something wrong with your thread future result.

    System.out.println("name is:"+future.get(i).get().getName());
    

    from this line I think there are some futures have no result and can be null, So you should check your code, if there are some Futures null,If so, get a if before this line executed.

提交回复
热议问题