Java Cron Jobs

Need to run a CRON Job in Java? Try out JobRunr for all your recurring java CRON jobs!

  • Ronald Dehuysser
  • November 10, 2021

Java Cron Jobs

What are CRON jobs?

CRON or crontab is a command-line utility to run certain tasks periodically at fixed times, dates, or intervals. CRON or crontab was originally created by AT&T Bell Laboratories in May 1975 and is by default now available on every OS. Most developers will know the Linux Crontab or the Windows Task Scheduler.

How are CRON jobs useful?

As a developer, you already might have encountered a business requirement where each morning at 10 o’clock a report needs to be sent via email. This is a typical example where a CRON job comes in handy: using a simple CRON expression (in this case 0 10 * * *), you can make sure the method is executed each morning at 10 o’clock.

How is a CRON expression created?

The CRON time string format exists of five fields that the CRON scheduler converts into a time interval. CRON then uses this interval to determine how often to run the associated task or method.

┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of the month (1 - 31) or L for last day of the month
│ │ │ ┌───────────── month (1 - 12 or Jan/January - Dec/December)
│ │ │ │ ┌───────────── day of the week (0 - 6 or Sun/Sunday - Sat/Saturday)
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
“* * * * *"

How to run a CRON job in Java?

Today, you have several possibilities to run CRON jobs in Java:

  • there is of course Quartz Scheduler
  • Spring framework has support for scheduled jobs using the @Scheduled annotation
  • and since JobRunr is now also in the picture, you can use JobRunr to run CRON jobs in Java.

What is the benefit of using JobRunr for Java CRON Jobs?

Using JobRunr for your CRON jobs brings some advantages:

  • you can easily create a CRON job in a 1-liner using JobRunr: BackgroundJob.scheduleRecurrently(Cron.daily(), () -> System.out.println("Easy!"));
  • if you are using Spring Framework, Micronaut or Quarkus: this is even easier. You can just add the JobRunr integration of your choice (jobrunr-spring-boot-starter, jobrunr-micronaut-feature or the jobrunr-quarkus-extension) and annotate the method that you want to schedule with the @Recurring annotation:
@Service
public class SampleService {

    @Recurring(id = "my-recurring-job", cron = "*/5 * * * *")
    @Job(name = "My recurring job")
    public void executeSampleJob() {
        // your business logic here
        // you can also conditionally enqueue a new job - better visibility in the dashboard
    }
}
  • it comes with a great UI where you have an overview of all your CRON jobs and where you check whether your CRON task / method finished successfully.
An overview of all recurring jobs with the ability to trigger or delete them
A detailed overview of a succeeded CRON job

The JobRunr Blog

Everything you need to know about
background processing

Explore technical deep-dives, product updates, and real-world examples to help you build, scale, and monitor your Java background jobs.

blog image

March 18, 2025

Optimizing Cost and Performance on Kubernetes: Scale Java Workloads with JobRunr Metrics

Explore how JobRunr Pro metrics API can dynamically scale your Java workloads on Kubernetes to optimize cost and performance.

Read More Details
blog image

October 5, 2022

JobRunr and Daylight Saving Time

Let’s dig deeper on the impact of Daylight Saving Time and scheduled JobRunr Jobs

Read More Details
blog image

April 9, 2024

JobRunr and JobRunr Pro v7.0.0!

We’re proud to announce the latest release, JobRunr & JobRunr Pro v7.0.0

Read More Details
call to action

Try JobRunr yourself, no install required

Walk through 21 hands-on scenarios in our hosted demo and feel how JobRunr handles real-world workflows. Open it in your browser, no setup, no signup.

Launch the interactive demo