JobRunr 5-Minute Quickstart Guide

Choose a framework:

Step 1: Add the JobRunr dependency

Add JobRunr to your project using Maven or Gradle. This quickstart uses the built-in in-memory storage, so we only need a json parser and we are ready to go.

We recommend using the latest version of JobRunr (e.g., 8.1.0).

Maven

<dependency> 
    <groupId>org.jobrunr</groupId> 
    <artifactId>jobrunr</artifactId> 
    <version>8.1.0</version> 
</dependency>
<!-- you can use either Jackson, Gson or Yasson (Json-B compatible).  -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.11.0</version>
</dependency>

Gradle

implementation 'org.jobrunr:jobrunr:8.1.0'

Tip: Are you using Spring, Micronaut or Quarkus? We created starters to get you going even quicker.

Step 2: Initialize JobRunr

In your application’s main method, configure and initialize JobRunr. We will use the simple InMemoryStorageProvider for this demo.

Create a MainApplication.java file and add the following code:

import org.jobrunr.configuration.JobRunr;
import org.jobrunr.storage.InMemoryStorageProvider;

public class MainApplication {

    public static void main(String[] args) {

        // Initialize JobRunr
        JobRunr.configure()
            .useStorageProvider(new InMemoryStorageProvider()) // No database needed
            .useBackgroundJobServer() // Starts the processing thread
            .useDashboard()           // Starts the dashboard at http://localhost:8000
            .initialize();
    }
}

Step 3: Schedule your first job

Now, let’s schedule a recurring job to run every minute. JobRunr uses CRON expressions for scheduling.

Add this code to your main method right after .initialize():

import org.jobrunr.configuration.JobRunr;
import org.jobrunr.storage.InMemoryStorageProvider;
import org.jobrunr.scheduling.BackgroundJob;
import org.jobrunr.scheduling.cron.Cron;

public class MainApplication {

    public static void main(String[] args) {

        // Initialize JobRunr
        JobRunr.configure()
            .useStorageProvider(new InMemoryStorageProvider())
            .useBackgroundJobServer()
            .useDashboard()
            .initialize();

        // Schedule your first recurring job
            BackgroundJob.scheduleRecurrently(
                "my-first-job",     // Optional id for this job
                Cron.every5minutes(), // A simple CRON expression
                () -> System.out.println("My recurring job is running!")
        );
    }
}

Tip: You can also run a job just once (fire-and-forget) using BackgroundJob.enqueue(() -> ...) or schedule it for the future with BackgroundJob.schedule(Instant.now().plusHours(1), () -> ...) .

Step 4: Watch it run

Run your MainApplication.java file. That’s it.

  1. Open your browser and go to http://localhost:8000/dashboard.
  2. You will see “my-first-job” listed in the Recurring Jobs tab.
  3. Click the Jobs tab. Within a minute, you will see your job processing live.
Animation of a recurring job being scheduled

What’s next?

You’ve just scheduled your first reliable, recurring job. Here is what to do next.

  • Use a Real Database: The InMemoryStorageProvider is great for testing. When you are ready, switch to a persistent database. See our documentation about storage to use JobRunring with your existing SQL or NoSQL database.
  • Save energy and costs with Carbon Aware Scheduling (v8+): Automatically schedule non-critical jobs to run when the grid’s carbon intensity is lowest. This optimizes your server’s energy consumption, helping to reduce your CO2 footprint and lower cloud utility costs. See the Carbon Aware documentation.
  • Using Spring Boot, Micronaut, or Quarkus? Our auto-configuration and dedicated integration packages make setup a one-liner. Have a look at the Spring Boot, Micronaut & Quarkus guides.
  • Prefer watching videos? Check-out our video tutorials on Youtube.
  • Example projects: We have different example projects on GitHub that help you start.
  • Explore JobRunr Pro: Ready to scale? JobRunr Pro offers priority queues, complex workflows, and a multi-cluster dashboard.