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

The FixedBackOffPolicy method setBackOffPeriod(long) if set to 0 or less than .The backOffPeriod value not is 1000ms. #224

Open
yahyaoo opened this issue Nov 6, 2020 · 1 comment

Comments

@yahyaoo
Copy link

yahyaoo commented Nov 6, 2020

Class: org.springframework.retry.backoff.FixedBackOffPolicy
Method: public void setBackOffPeriod(long backOffPeriod)

source code:


	private static final long DEFAULT_BACK_OFF_PERIOD = 1000L;

	private volatile long backOffPeriod = DEFAULT_BACK_OFF_PERIOD;

	....//omit

	public void setBackOffPeriod(long backOffPeriod) {
		this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : 1); //here
	}

	....//omit
	

suggest code:


	private static final long DEFAULT_BACK_OFF_PERIOD = 1000L;

	private volatile long backOffPeriod = DEFAULT_BACK_OFF_PERIOD;

	....//omit

	public void setBackOffPeriod(long backOffPeriod) {
		this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : DEFAULT_BACK_OFF_PERIOD); //here
	}

	....//omit
	
@yahyaoo
Copy link
Author

yahyaoo commented Nov 6, 2020

test code:

    @Test
    public void fixedBackOffPolicyTest() {
        FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
        backOffPolicy.setBackOffPeriod(0);
        RetryTemplate retryTemplate = RetryTemplate.builder()
                .customBackoff(backOffPolicy)
                .build();

        Object execute = null;
        try {
            execute = retryTemplate.execute(new RetryCallback<Object, Throwable>() {
                @Override
                public Object doWithRetry(RetryContext context) throws Throwable {
                    log.info("RetryCallback:" + context.getRetryCount());
                    throw new IllegalArgumentException();
                    //return "RetryCallback";
                }
            }, new RecoveryCallback<Object>() {
                @Override
                public Object recover(RetryContext context) throws Exception {
                    log.info("RecoveryCallback:" + context.getRetryCount());
                    return "RecoveryCallback";
                }
            });
        } catch (Throwable throwable) {
            log.error(throwable.getMessage(), throwable);
        }

        log.info("result:" + execute);
    }

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