public List<ClientResponse> findAllRepositoriesByUsername(String username) {
long start = System.currentTimeMillis();
List<RepositoriesResponseAPI> userRepositories = makeRequestForUserRepositories(username);
List<ClientResponse> clientData = new LinkedList<>();
ExecutorService executorService = Executors.newFixedThreadPool(checkBestThreadNumber(userRepositories));
userRepositories.forEach(repository -> { executorService.execute(() -> {
List<BranchesResponseAPI> repositoryBranches = makeRequestForRepositoryBranches(repository.owner().login(), repository.name());
ClientResponse clientResponse = MapperResponseAPI.mapToClientResponse(repository, repositoryBranches);
synchronized (clientData) {
clientData.add(clientResponse);
}
});
});
executorService.shutdown();
try {
executorService.awaitTermination(THREADS_WAITING_TIME, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println(System.currentTimeMillis()-start);
return clientData;
}
You think its good or there is something dangerous? And what I can do by alternative? Is clientData as an key good option?