Skip to content

[Proposal] Create new standalone method level @Scheduled #684

@hantsy

Description

@hantsy

In Concurrency 3.1, the new @Schedule annotation that nested in @Asynchronous has some issues in the real world applications.

  1. The attributes hour/minute/second etc., are just another duplicated form of the cron.
  2. It does not cover the simple fixedRate/interval case.

I hope there is a new annotation that refer to the definition from Spring @Scheduled, cover both simple fixed rate settings and cron expression, also consider EL (via Jakarta Config properties/env) support.

public @interface Scheduled { // a modified versoin of spring @Scheduled
	String cron() default ""; //also should support EL
	ZoneId zone() default UTC;
	long fixedRate() default -1;
	String fixedRateExpression() default ""; // accept EL
	long fixedDelay() default -1;
	String fixedDelayExpression() default ""; // accept EL
	long initialDelay() default -1;
	String initialDelayExpression() default ""; // accept EL
	TimeUnit timeUnit() default TimeUnit.MILLISECONDS;
	String executor() default ""; //scheduledExecutorService name or change it to Qualifier to match the executor to run this scheudule
}

Of course, in theory, it is possible to add the missing attributes to the existing @Schedule.

However, if we add the missing fixedRate related attributes to @Schedule and allow it to use on methods, then we will face another issue: we have to add a executor attribute to @Schedule to set up the executor service used to run the scheduling tasks, which make the @Asychronous looks weird, because @Asynchronous itself includes an executor.

@Schedule(executor=...)
public void aMethod()

@Asynchronous(executor=..., runAt={@Schedule(executor=...)}...)
public void bMethod()

Originally it is discussed here, #624 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions