MMS • Andrea Messetti
Article originally posted on InfoQ. Visit InfoQ
JobRunr, a Java library designed to handle background tasks in a reliable manner within a JVM instance, released the new version 6.0 after a year of development since the release of version 5.0 in March 2022.
With the latest update, JobRunr introduces several new features, including JobBuilders which allow developers to configure all aspects of a job using a builder API:
jobScheduler.create(aJob()
.withName("My Scheduled Job")
.scheduleAt(Instant.parse(scheduleAt))
.withDetails(() -> service.doWork()));
And JobLabels which allow tagging of jobs with custom labels:
@Job(name="My Job", labels={"fast-running-job", "tenant-%0"})
void myFastJob(String tenandId) {
// your business logic
}
The server name is now also visible in the dashboard, along with MDC Support for logging during the success and failure of a job. It also comes with the support of Spring Boot 3 AOT with a new starter.
In terms of performance improvements, JobRunr has optimized the enqueueing of jobs and integrated MicroMeter for metrics tracking of enqueued, failed and succeeded jobs on each BackgroundJobServer
but this is now opt-in. Additionally, the library has made stability improvements to handle exceptions and prevent job processing in case of a database outage.
Created by Ronald Dehuysser, JobRunr was first introduced to the Java community in April 2020. It provides a unified programming model for creating and executing background jobs with minimum dependencies and low overhead. Jobs can be easily created using Java 8 lambdas, which can be either CPU or I/O intensive, long-running or short-running.
JobRunr guarantees execution by a single scheduler instance using optimistic locking, ensuring that jobs are executed only once. For persistence, it supports both RDBMS (Postgres, MariaDB/MySQL, Oracle, SQL Server, DB2, and SQLite) and NoSQL (ElasticSearch, MongoDB, and Redis). The library has a minimal set of dependencies, including ASM, slf4j, and either Jackson, gson, or a JSON-B compliant library. It also includes a dashboard to control the tasks running in the background and see the job history.
The Pro version adds the capability to define priority queues and to create background jobs in batch.
In conclusion, JobRunr is a simple and effective library for handling background jobs in Java applications. Its ability to support different storage options, optimized performance, and enhanced stability makes it a suitable choice for a wide range of use cases. JobRunr can manage the execution of background tasks, whether they are deployed in the cloud, on shared hosting or in a dedicated environment.