Skip to content

Support for a really lightweight scheduler using JDKs ScheduledExecutorService #7

@norbertroamsys

Description

@norbertroamsys

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 ;-).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions