Skip to main content

Practice ยท 3 of 3

Retry with Backoff (Counted, Not Slept)

Implement static int attemptsToSucceed(FlakyTransport t, String url) in Solution: - interface FlakyTransport { int attempt(String url); } โ€” returns the HTTP status it "got": 200, or a 5xx. - attemptsToSucceed calls attempt() repeatedly until it returns 200 (immediately retryable: 5xx), with a MAX of 3 retries (4 calls total); return the attempt number (1-based) on which 200 arrived, or -1 if still failing. - 4xx stops immediately with -1 (client errors are not retryable). No Thread.sleep โ€” backoff timing is infrastructure; the *policy* is what you're implementing.

Difficulty: intermediate

Back to lesson: Practice: Async & HTTP Lab