Hi I wanted to know what's the right approach to refresh access tokens inside java code. So currently the APIs am consuming expect an access token in the request body for authorization. So I retrieve the access token first by making an API call to /tokens/ API and add the retrieved token to the data API calls that I subsequently consume. But the token expires every 5 minutes.
So would it be a right approach if I make a call to /tokens/ API once I get a 4xx Not Authorized response from the data API calls. Or should I run a thread in the background which retrieves the access token every 5 minutes.