I am making multiple REST API request calls to a third party app from java and I do not know the threshold value of number of requests they procees in a given time and I am thrown a 429 too many requests runtime exception, I need to add a delay between these API calls can anyone suggest an optimal way(there are no threads used in the app)
Asked
Active
Viewed 1,243 times
1
-
1you can use thread.sleep. There will be the main thread doing its job. You can use sleep in that main thread. – Karthik Surianarayanan Feb 18 '14 at 08:56
1 Answers
4
You can use Handler.postDelayed()
method:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// do something that is meant to be delayed
}
}, delayMillis);
where delayMillis
is delay time measured in milliseconds.

Piotr Chojnacki
- 6,837
- 5
- 34
- 65