I\'m writing some reconnect logic to periodically attempt to establish a connection to a remote endpoint which went down. Essentially, the code looks like this:
I'm using AOP and Java annotations. There is a ready-made mechanism in jcabi-aspects (I'm a developer):
@RetryOnFailure(attempts = 3, delay = 1, unit = TimeUnit.SECONDS) public void establishConnection() { this.connection = newConnection(); }
ps. You can also try RetryScalar from Cactoos.
RetryScalar