Loop 10 times for each request. If it succeeds, just break out. Is it necessary to use the database? How to judge failure: Set the timeout to 30s. No response for 30s is a failure. Others can be judged by yourself based on the returned httpCode and the returned data content. How to time a request every 30s: Record the start of each request. time, when the judgment fails, check whether the current time and the request start time are 30s apart. If 30s has been reached, directly perform the loop request, otherwise use Thread.sleep (30-interval) to sleep the thread, and continue the request after getting up.
If you want to do batch operations, Quartz is fine. If you don’t want to use Quartz, you can also use ScheduledThreadPoolExecutor. Timer is not recommended. If you want to reduce complexity, you can use this method of retrying a single task.
If this request fails, you need to judge the url http code
That’s it. I can’t think of any better way than this
In fact, the title already abstractly explains the implementation.
The question is what problem does this requirement solve?
Loop 10 times for each request. If it succeeds, just break out. Is it necessary to use the database?
How to judge failure:
Set the timeout to 30s. No response for 30s is a failure. Others can be judged by yourself based on the returned httpCode and the returned data content.
How to time a request every 30s:
Record the start of each request. time, when the judgment fails, check whether the current time and the request start time are 30s apart. If 30s has been reached, directly perform the loop request, otherwise use Thread.sleep (30-interval) to sleep the thread, and continue the request after getting up.
If you want to do batch operations, Quartz is fine. If you don’t want to use Quartz, you can also use ScheduledThreadPoolExecutor. Timer is not recommended.
If you want to reduce complexity, you can use this method of retrying a single task.
It can also be implemented on the front end, using JQuery’s AJAX asynchronous request
Java also has its own timer, try using a timer
I want to know what the business scenario is like. If I loop 10 times, I will break after judging the success