Android OkHttp, refresh expired token

后端 未结 5 1142
我寻月下人不归
我寻月下人不归 2021-01-30 18:14

Scenario: I am using OkHttp / Retrofit to access a web service: multiple HTTP requests are sent out at the same time. At some point the auth token expires, and

5条回答
  •  一向
    一向 (楼主)
    2021-01-30 19:07

    Edited for thread safety

    Havent looked at OkHttp or retrofit but how about having a static flag that is set as soon as a token fails and check for that flag before you request a new token?

    private static AtomicBoolean requestingToken = new AtomicBoolean(false);
    
    //..... 
    if (requestingToken.get() == false)
     {
        requestingToken.set(true);
        //.... request a new token
     }
    

提交回复
热议问题