Apply timeout control around Java operation

前端 未结 7 872
滥情空心
滥情空心 2021-02-07 06:54

I\'m using a third party Java library to interact with a REST API. The REST API can sometimes take a long time to respond, eventually resulting in a java.net.ConnectExcept

7条回答
  •  执笔经年
    2021-02-07 07:24

    Now we have our nice CompletableFuture , here an application to achieve what was asked.

    CompletableFuture.supplyAsync(this::foo).get(15, TimeUnit.SECONDS)
    

提交回复
热议问题