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

[Use Case]: Autostart for Scheduled Asynchronous methods #624

Open
1 of 4 tasks
njr-11 opened this issue Oct 29, 2024 · 1 comment
Open
1 of 4 tasks

[Use Case]: Autostart for Scheduled Asynchronous methods #624

njr-11 opened this issue Oct 29, 2024 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@njr-11
Copy link
Contributor

njr-11 commented Oct 29, 2024

As a ...

  • Application user/user of the configuration itself
  • API user (application developer)
  • SPI user (container or runtime developer)
  • Specification implementer

I need to be able to ...

arrange for an Asynchronous method to be automatically submitted/scheduled upon application startup

Which enables me to ...

more conveniently code applications that have business logic that should run on a schedule

Additional information

This requirement was discussed in a topic titled "Defining Jakarta EE 12 Scope in Program Plan" on the jakarta.ee-community mailing list.

One way to achieve this might be with a boolean autoSchedule field,

 @Asynchronous(runAt = @Schedule(daysOfWeek = DayOfWeek.TUESDAY, hours = 1),
               autoSchedule = true)
 public void weeklyTask() {
     ...
 }

Alternatively, instead of a boolean, we could use a long value, being a delay (in milliseconds? seconds? which unit is best?) to automatically start after. The default of -1 would mean don't automatically schedule on application startup, keeping existing applications compatible.

 @Asynchronous(runAt = @Schedule(daysOfWeek = DayOfWeek.TUESDAY, hours = 1),
               scheduleAfter = 1000)
 public void weeklyTask() {
     ...
 }

If we wanted, we could also allow it for one-time Asynchronous methods without a Schedule, in which case the name would need to be something more general like autoSubmit or submitAfter instead of autoSchedule or scheduleAfter.

@njr-11 njr-11 added the enhancement New feature or request label Oct 29, 2024
@njr-11 njr-11 added this to the 3.2.0 milestone Oct 29, 2024
@hantsy
Copy link

hantsy commented Dec 25, 2024

As EJB and Spring do, make sure all @Scheduled based scheduled tasks are scanned at deployment time and started automatically as the application is deployed.

Developers can control more details of the scheduled task by programmatic APIs, auto or not, conditionally generate the schedule settings, etc.

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

No branches or pull requests

2 participants