There are a couple of libraries like that: they are mostly connected with some resilience packages, but I wouldn't bother in this case (although maybe you're interested in something like resilience4j, but in my opinion that's very large framework and you need some library, like this Guava RetryingI ...