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

Missing skip- or exclusive-feature for Scheduler system #9883

Closed
McIntozh opened this issue Jun 9, 2020 · 3 comments · Fixed by #10338
Closed

Missing skip- or exclusive-feature for Scheduler system #9883

McIntozh opened this issue Jun 9, 2020 · 3 comments · Fixed by #10338
Assignees
Labels
Milestone

Comments

@McIntozh
Copy link

McIntozh commented Jun 9, 2020

Description
I encountered the problem, that when the triggered method is currently processing and the same timer hits again, the method is also processed again.
Migrating from the EJB @Schedule annotation, this is a different behaviour. In EJB the method is processed exclusively, and during that, additional triggers are ignored.

I tried setting the method to synchronized but then - like I expected - the triggers are stacking up, firing again as soon as the method finishes.

Only current workaround is

  private boolean running = false;
  @Scheduled(cron = "* * * * * *")
  public void doSomethingThatSometimesTakesLonger() {
    if (running) {
      return;
    }
    running = true;
    try {
      ...Method code...
    } finally {
      running = false;
    }
  }

I would like to have the possibility to skip triggers on methods that are still being processed

Implementation ideas
Either:

  • Add a configuration property
  • Add a property to the @Scheduler annotation
@McIntozh McIntozh added the kind/enhancement New feature or request label Jun 9, 2020
@McIntozh McIntozh changed the title Missing skip- order exclusive-feature for Scheduler system Missing skip- or exclusive-feature for Scheduler system Jun 9, 2020
@mkouba
Copy link
Contributor

mkouba commented Jun 29, 2020

I think that we should definitely address this. Your workaround is OK except that the running field should be volatile or even an AtomicBoolean:

private final AtomicBoolean running = new AtomicBoolean();

@Scheduled(cron = "* * * * * *")
public void doSomethingThatSometimesTakesLonger() {
    if (running.compareAndSet(false, true)) {
       try {
         ...Method code...
       } finally {
        running.set(false);
       }
    }
  }

@mkouba
Copy link
Contributor

mkouba commented Jun 29, 2020

I've created a draft PR here: #10338

@McIntozh
Copy link
Author

McIntozh commented Jul 2, 2020

I haven't had time to test this, but on first sight it looks like what I wanted :)

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

Successfully merging a pull request may close this issue.

2 participants