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

Support for a really lightweight scheduler using JDKs ScheduledExecutorService #7

Open
norbertroamsys opened this issue Oct 19, 2021 · 1 comment

Comments

@norbertroamsys
Copy link

This issue is to discuss the opportunity to share the code suggested in jmrozanec/cron-utils#491 within this module.
The pull requests has been closed because the functionality is more related to this extension module.

@jmrozanec : I checked the code in detail and found the following really important difference in the design of both solutions.

Your approach: Jobs a managed by additional polling thead(s) that check the trigger (usually by calling ExecutionTime.forCron(cron).nextExecution(ZonedDateTime.now()))

Our approach: Use ScheduledExecutorService.schedule() by calculating a "delay":

...
    private ZonedDateTime nextExecution;
...
    /**
     * Plans the next execution time to run this job again.
     *
     * @param timeStamp the reference time stamp
     */
    private void scheduleNext(final ZonedDateTime timeStamp) {
        final Optional<ZonedDateTime> next = executionTime.nextExecution(timeStamp);
        if (next.isPresent()) {
            nextExecution = next.get();
            final long delay = ChronoUnit.MILLIS.between(timeStamp, nextExecution);
            scheduledFuture = executorService.schedule(this, delay, TimeUnit.MILLISECONDS);
        } else {
            // job maybe defined to run only once
            scheduledFuture = null;
        }
    }

Advantage:

  • It's more lightweight and simple in general
  • No extra polling threads needed

Disadvantage:

  • No concept for more general Execution trigger
  • Scheduling of jobs other than calculated by Cron expressions maybe out-of-scope

So my question:
Is scheduling of non-Cron based jobs really a requirement?
If yes I would think our approach does not fit or can only be provided in addition to the current one.
If no I would suggest to re-code the scheduling using "our" approach.

Please let me know how we should go on!
And please be aware: No rush! This task will be done by me in my "private time" anyway ;-).

@jmrozanec
Copy link
Owner

@norbertroamsys we appreciate the work done so far! Thanks! 😄 We will have a look at the code, think about scenarios we are willing to address, and come back with an answer! 😄 🚀

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

2 participants