This is my method:
private List<OfficerAccountFilter> createResult(List<Account> accountList) {
List<List<Account>> partedList = Lists.partition(accountList, MAX_LIMIT);
List<OfficerAccountFilter> result = new ArrayList<>();
System.out.println("size of account" + accountList.size());
int size = accountList.size() / 800;
ExecutorService executorService = Executors.newFixedThreadPool(NTHREDS);
List<Future<List<OfficerAccountFilter>>> futureList = new ArrayList<Future<List<OfficerAccountFilter>>>();
for (int i = 0; i <= size + 1; i++) {
Callable<List<OfficerAccountFilter>> worker = new AccountCallable(accountList);
Future<List<OfficerAccountFilter>> submit = executorService.submit(worker);
futureList.add(submit);
}
for (Future<List<OfficerAccountFilter>> future : futureList) {
try {
result = future.get();
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
executorService.shutdown();
return result;
}
my callable class:
public class AccountCallable implements Callable<List<OfficerAccountFilter>> {
@Autowired
private OfficerAccountSOAPRunner officerAccountSOAPRunner;
private List<Account> accountList;
public AccountCallable(List<AccountIdentifier> accountList) {
this.accountList = accountList;
}
@Override
public List<OfficerAccountFilter> call() throws Exception {
List<OfficerAccountFilter> result = new ArrayList<>();
for (Account account : accountList) {
OfficerAccountRequest request = new OfficerAccountRequest();
request.getAccounts().add(account);
List<OfficerAccountFilter> accounts = officerAccountSOAPRunner.getAccounts(request);
result.addAll(accounts);
}
return result;
}
}
officerAccountSOAPRunner.getAccounts(request);
this is where im invoking Soap service which gives the filtered accounts back to officer. Not sure why is it returning null at this point. If i do it sequentially, it works absolutely fine. Am i not setting the future Object right?
Error stack:
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at com.test.service.impl.OfficerServiceImpl.createResult(OfficerServiceImpl.java:92)
at com.test.ServiceImpl.limitOfficerAccounts(OfficerServiceImpl.java:61)
at com.test.service.impl.OfficerServiceImpl.getOfficerAccounts(OfficerServiceImpl.java:54)
Caused by: java.lang.NullPointerException
at com.test.impl.AccountIdentifierCallable.call(AccountCallable.java:36)
at com.test.impl.AccountIdentifierCallable.call(AccountCallable.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
The error is SOAPRunner call: List<OfficerAccountFilter> accounts = officerAccountSOAPRunner.getAccounts(request);
I put it in debug mode and it's coming as soon as i set on @Autowired. So it's coming from there. Do i need to set the cope differently?
createResult
for? You are always passing the completeaccountList
into your callables, so you don't need more than one callable created. Second, which line is throwing theNullPointerException
?