I'm trying to use parallel streams to call an API endpoint to get some data back. I am using an ArrayList<String> and sending each String to a method that uses it in making a call to my API. I have setup parallel streams to call a method that will call the endpoint and marshall the data that comes back. The problem for me is that when viewing this in htop I see ALL the cores on the db server light up the second I hit this method ... then as the first group finish I see 1 or 2 cores light up. My issue here is that I think I am truly getting the result I want ... for the first set of calls only and then from monitoring it looks like the rest of the calls get made one at a time.
I think it may have something to do with the recursion but I'm not 100% sure.
private void generateObjectMap(Integer count){ ArrayList<String> myList = getMyList(); myList.parallelStream().forEach(f -> performApiRequest(f,count)); } private void performApiRequest(String myString,Integer count){ if(count < 10) { TreeMap<Integer,TreeMap<Date,MyObj>> tempMap = new TreeMap(); try { tempMap = myJson.getTempMap(myRestClient.executeGet(myString); } catch(SocketTimeoutException e) { count += 1; performApiRequest(myString,count); } ... else { System.exit(1); } }