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

@RefreshScope doesn't affect @Scheduled methods #97

Closed
sqshq opened this Issue Mar 2, 2016 · 4 comments

Comments

Projects
None yet
4 participants
@sqshq

sqshq commented Mar 2, 2016

I'm using Cloud Config Server and Client. Everything works perfectly, except dynamic properties refresh in @scheduled methods.

Here is a Controller and scheduled method (all in one class, for clear example):

@RestController
@RefreshScope
public class NotificationController {

    @Value("${delay.value}")
    private String value;

    @RequestMapping(path = "/value", method = RequestMethod.GET)
    public String getValue() {
        return value;
    }

    @Scheduled(fixedDelayString = "${delay.value}")
    public void print() {
        System.out.println(value);
    }
}

When I update delay.value in Config Server and refresh Client with curl -XPOST http://localhost:8080/refresh, I can see that change with controller getValue() method.

But print() method continues printing old value with the same delay.

It doesn't seem to me as expected behavior, and I can't find this limitation in documentation.

If it is not a known issue, I can share a minimal sample project.

@dsyer

This comment has been minimized.

Show comment
Hide comment
@dsyer

dsyer Mar 2, 2016

Contributor

It's a known issue and it can't be fixed in Spring Cloud as far as I know. The scheduling infrastructure doesn't know that you want to change the trigger and it is the trigger that needs to be refreshed not the bean with the @Scheduled annotation. If you want, we can document the limitation.

I think you can achieve your goal by configuring the trigger manually and making that into a bean in @RefreshScope.

Contributor

dsyer commented Mar 2, 2016

It's a known issue and it can't be fixed in Spring Cloud as far as I know. The scheduling infrastructure doesn't know that you want to change the trigger and it is the trigger that needs to be refreshed not the bean with the @Scheduled annotation. If you want, we can document the limitation.

I think you can achieve your goal by configuring the trigger manually and making that into a bean in @RefreshScope.

@sqshq

This comment has been minimized.

Show comment
Hide comment
@sqshq

sqshq Mar 2, 2016

Ok, thank you for clearing that up. I'll configure my trigger manually.

sqshq commented Mar 2, 2016

Ok, thank you for clearing that up. I'll configure my trigger manually.

@spencergibb spencergibb closed this Mar 2, 2016

@magaton

This comment has been minimized.

Show comment
Hide comment
@magaton

magaton Jun 6, 2016

Could you provide an example how to configure the trigger manually?

magaton commented Jun 6, 2016

Could you provide an example how to configure the trigger manually?

@dsyer

This comment has been minimized.

Show comment
Hide comment
@dsyer

dsyer Jun 6, 2016

Contributor

Look at SchedulingConfigurer (javadocs are fairly clear, but you can probably find samples on the interweb as well if you want to copy-paste).

Contributor

dsyer commented Jun 6, 2016

Look at SchedulingConfigurer (javadocs are fairly clear, but you can probably find samples on the interweb as well if you want to copy-paste).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment