I have below method in my application and it's looks working fine.. but i m not sure how it is...
ArrayList arr = new ArrayList();
Collection<Future<?>> futures = new LinkedList<Future<?>>();
RestCallThread thread = null;
HttpHeaders header = getAuthHeader(authorization);
for(String ids: IDS){
thread = new RestCallThread(ids,header);
futures.add(executor.submit(thread));
}
for(Future<?> future : futures)
{
try
{
arr.add(future.get());
}
catch (InterruptedException | ExecutionException e)
{
e.printStackTrace();
}
} return arr;
In the code RestAPI calls are added to the ThreadPoolExecutor and waiting for the result..
My Question is Since the approach is based on thread how the return statement is not executed till all the API threads get completed...
Any chance of return statement will return empty list?
Aucun commentaire:
Enregistrer un commentaire