Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use invokeAll() to let all thread pool do their task?
    text
    copied!<pre><code> ExecutorService pool=Executors.newFixedThreadPool(7); List&lt;Future&lt;Hotel&gt;&gt; future=new ArrayList&lt;Future&lt;Hotel&gt;&gt;(); List&lt;Callable&lt;Hotel&gt;&gt; callList = new ArrayList&lt;Callable&lt;Hotel&gt;&gt;(); for(int i=0;i&lt;=diff;i++){ String str="2013-"+(liDates.get(i).get(Calendar.MONTH)+1)+"-"+liDates.get(i).get(Calendar.DATE); callList.add(new HotelCheapestFare(str)); } future=pool.invokeAll(callList); for(int i=0;i&lt;=future.size();i++){ System.out.println("name is:"+future.get(i).get().getName()); } </code></pre> <p>Now I want pool to <code>invokeAll</code> all the task before getting to the for loop but when I run this program for loop gets executed before that <code>invokeAll</code> and throws this exception:</p> <pre><code>java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source) at java.util.concurrent.FutureTask.get(Unknown Source) at com.mmt.freedom.cheapestfare.TestHotel.main(TestHotel.java:6‌​5) Caused by: java.lang.NullPointerException at com.mmt.freedom.cheapestfare.HotelCheapestFare.getHotelCheap‌estFare(HotelCheapes‌​tFare.java:166) at com.mmt.freedom.cheapestfare.HotelCheapestFare.call(HotelChe‌​apestFare.java:219) at com.mmt.freedom.cheapestfare.HotelCheapestFare.call(HotelChe‌​apestFare.java:1) at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) atjava.util.concurrent.ThreadPoolExecutor$Worker.run(Unknow‌​n Source) at java.lang.Thread.run </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload