title: Spring boot Async rest call
body: <p>I am trying to create a scheduler that sends a get request to a web service and gets the count of the items we need. then divide the Total by per_page then send any number of requests needed but requests are Async.</p>
  
  <p>my code is working perfectly fine in my test class but in the main Application im getting two error based on the JDK version </p>
  
  <p>this is my API service :</p>
  
  <pre><code>    public interface RestService {
  
      @Async
      CompletableFuture&lt;UpcomingEventsResponse&gt; getUpcomingEvents(int page,String day, String token);
  
      UpcomingEventsResponse getUpcomingEvents(String day,String token);
  }
  </code></pre>
  
  <p>my RestService Impl:</p>
  
  <pre><code>@Service
  @RequiredArgsConstructor
  @Slf4j
  public class RestServiceImpl implements RestService {
  
      public static final String UPCOMING_EVENTS_URL = "HTTP://localhost/test";
      private final RestTemplate restTemplate;
  
      @Override
      public CompletableFuture&lt;UpcomingEventsResponse&gt; getUpcomingEvents(int page,String day, String token) {
          String url = createUrl(UPCOMING_EVENTS_URL,createQuery("day",day),createQuery("page", page), createQuery("token", token));
  
          return makeCallAsync(url,HttpMethod.GET,null,UpcomingEventsResponse.class);
      }
  
      @Override
      public UpcomingEventsResponse getUpcomingEvents(String day,String token) {
          String url = createUrl(UPCOMING_EVENTS_URL,createQuery("day",day), createQuery("page", 1), createQuery("token", token));
  
          return makeCall(url,HttpMethod.GET,null,UpcomingEventsResponse.class);
      }
  
      private &lt;T&gt; T makeCall(String url,
                             HttpMethod method,
                             HttpEntity&lt;Object&gt; httpEntity,
                             Class&lt;T&gt; outClass) {
  
          return restTemplate.exchange(url, method, httpEntity, outClass).getBody();
      }
  
      private &lt;T&gt; CompletableFuture&lt;T&gt; makeCallAsync(String url,
                                                     HttpMethod method,
                                                     HttpEntity&lt;Object&gt; httpEntity,
                                                     Class&lt;T&gt; outClass) {
  
          return CompletableFuture.completedFuture(restTemplate.exchange(url, method, httpEntity, outClass).getBody());
      }
  }
  </code></pre>
  
  <p>and this is my scheduler class :</p>
  
  <pre><code>@Component
  @RequiredArgsConstructor
  @Slf4j
  public class EventScheduler {
  
      private final RestService restService;
  
      //TODO change time
      @Scheduled(cron = "0 */2 * * * *")
      public void getAllEvents(){
          long start = System.currentTimeMillis();
  
          //TODO add token from database or env
  
          UpcomingEventsResponse upcomingEvents = restService.getUpcomingEvents(null, "token");
  
          List&lt;ResultsItem&gt; resultsItems = new ArrayList&lt;&gt;(upcomingEvents.getResults());
          List&lt;CompletableFuture&lt;UpcomingEventsResponse&gt;&gt; completableFutures = new ArrayList&lt;&gt;();
  
          int repeatTimes = upcomingEvents.getPager().getTotal() / upcomingEvents.getPager().getPerPage();
  
          for (int i = 0; i &lt; repeatTimes; i++) {
  
              int page = i + 2;
  
              CompletableFuture&lt;UpcomingEventsResponse&gt; events = restService.getUpcomingEvents(page, null, "token");
              completableFutures.add(events);
          }
  
          CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).join();
  
          log.info("Elapsed time: " + (System.currentTimeMillis() - start));
  
          completableFutures.forEach(completableFuture -&gt; {
              try {
                  resultsItems.addAll(completableFuture.get().getResults());
              } catch (InterruptedException | ExecutionException e) {
                  e.printStackTrace();
              }
          });
          log.info("Size " + resultsItems.size());
          log.info("Total " + upcomingEvents.getPager().getTotal());
      }
  
  }
  </code></pre>
  
  <p>and this is the error I'm getting in JDK 8: </p>
  
  <pre><code>peer not authenticated; nested exception is javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
  </code></pre>
  
  <p>and this is the error on JDK 10 or 11 : </p>
  
  <pre><code>javax.net.ssl.SSLException: No PSK available. Unable to resume
  </code></pre>
  
  <p>is there a better way to do this? and what is the problem? is this a bug?</p>