package w11; public class RetryUtils { private static final long BASE_DELAY_MS = 500; @FunctionalInterface public interface RetryTask { T run() throws Exception; } public static T retry(int maxRetries, RetryTask task) throws Exception { int attempt = 0; while (true) { try { return task.run(); } catch (Exception e) { if (attempt >= maxRetries) { throw e; } long delay = BASE_DELAY_MS * (1L << attempt); Thread.sleep(delay); attempt++; } } } }