Design pattern for “retrying” logic that failed?

后端 未结 11 1306
挽巷
挽巷 2020-12-07 16:10

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:



        
11条回答
  •  既然无缘
    2020-12-07 17:05

    If you are using java 8, this may helps.

    import java.util.function.Supplier;
    
    public class Retrier {
    public static  Object retry(Supplier function, int retryCount) throws Exception {
         while (0 {
                System.out.println(5/0);
                return null;
            }, 5);
        } catch (Exception e) {
            System.out.println("Exception : " + e.getMessage());
        }
    }
    }
    

    Thanks,

    Praveen R.

提交回复
热议问题