Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I run demo , when successNum coming my process can not exit immediately #92

Open
minhuicn opened this issue Nov 19, 2019 · 0 comments

Comments

@minhuicn
Copy link

minhuicn commented Nov 19, 2019

public static void main(String[] args) {
Retryer retryer = RetryerBuilder.newBuilder()
.retryIfException()
.retryIfResult(aBoolean -> Objects.equals(aBoolean, false))
.withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
.withStopStrategy(StopStrategies.stopAfterAttempt(20))
.withRetryListener(new RetryLogListener())
.withAttemptTimeLimiter(AttemptTimeLimiters.fixedTimeLimit(5, TimeUnit.SECONDS))
.build();
Callable callable = buildCallable(3, 10);
Boolean result = retryer.call(callable);
System.out.println("result = " + result);
}

public static final Callable<Boolean> buildCallable(int successNum, int maxCount) {
    Callable<Boolean> callable = new Callable<Boolean>() {
        int times = 0;

        @Override
        public Boolean call() throws Exception {
            times++;
            log.info("call times={}", times);
            if (successNum == times || times == maxCount) {
                return true;
            }
            if (times == 1) {
                throw new NullPointerException();
            } else if (times == 2) {
                throw new Exception();
            } else if (times == 3) {
                throw new RuntimeException();
            } else if (times == 4) {
                return false;
            } else {
                return false;
            }
        }
    };
    return callable;
}

where is wrong ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant