Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导异步rest调用_Java_Spring_Spring Boot_Asynchronous_Resttemplate - Fatal编程技术网

Java Spring引导异步rest调用

Java Spring引导异步rest调用,java,spring,spring-boot,asynchronous,resttemplate,Java,Spring,Spring Boot,Asynchronous,Resttemplate,我正在尝试创建一个调度器,它向web服务发送get请求,并获取我们需要的项目数。然后将总数除以每页,然后发送所需的任意数量的请求,但请求是异步的 我的代码在我的测试类中运行得非常好,但是在主应用程序中,基于JDK版本,我得到了两个错误 这是我的API服务: public interface RestService { @Async CompletableFuture<UpcomingEventsResponse> getUpcomingEvents(int

我正在尝试创建一个调度器,它向web服务发送get请求,并获取我们需要的项目数。然后将总数除以每页,然后发送所需的任意数量的请求,但请求是异步的

我的代码在我的测试类中运行得非常好,但是在主应用程序中,基于JDK版本,我得到了两个错误

这是我的API服务:

    public interface RestService {

    @Async
    CompletableFuture<UpcomingEventsResponse> getUpcomingEvents(int page,String day, String token);

    UpcomingEventsResponse getUpcomingEvents(String day,String token);
}
这是JDK 10或11上的错误:

javax.net.ssl.SSLException: No PSK available. Unable to resume

有更好的方法吗?问题是什么?这是一个bug吗?

问题出在Web服务中,尽管我真的无法理解不同JDK中出现错误的原因。据我所知,这是一个已知的错误,你可以阅读更多关于它

这个实现工作得很好,您可以使用resttemplate,但不能使用或

@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<ResultsItem> resultsItems = new ArrayList<>(upcomingEvents.getResults());
        List<CompletableFuture<UpcomingEventsResponse>> completableFutures = new ArrayList<>();

        int repeatTimes = upcomingEvents.getPager().getTotal() / upcomingEvents.getPager().getPerPage();

        for (int i = 0; i < repeatTimes; i++) {

            int page = i + 2;

            CompletableFuture<UpcomingEventsResponse> 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 -> {
            try {
                resultsItems.addAll(completableFuture.get().getResults());
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        });
        log.info("Size " + resultsItems.size());
        log.info("Total " + upcomingEvents.getPager().getTotal());
    }

}
peer not authenticated; nested exception is javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
javax.net.ssl.SSLException: No PSK available. Unable to resume