Task Schedulers in Java: Modern Alternatives to Quartz Scheduler
November 28, 2024Quartz is often considered the standard job scheduling library in Java, which can lead developers to overlook more modern alternatives.
For a long time, Quartz, also known as Quartz Scheduler, was the only viable open-source task scheduler in Java. In fact, the official Quartz documentation still suggests that there is no real alternative. In this article, we will list a few different Quartz alternatives that offer a similar set of features while being easier and more enjoyable to use.
Quartz Scheduler: how good is it really?
Similar to its alternatives, Quartz Scheduler can be integrated into almost any Java application to schedule and process any task implemented in Java. In its decades of existence, Quartz has evolved into a feature-rich framework for persisting task states, automatically retrying tasks on failure, defining complex schedules, prioritizing tasks, achieving distributed processing, and more.
The fact that Quartz has been around for so long has two major advantages: the library is battle-tested and has a large community, which makes it easier to find help. All these elements together make it the most popular job scheduling library in Java. Despite all these strengths, choosing Quartz is no longer so obvious due to some glaring issues.
Limitations of Quartz
Quartz is showing its age
Quartz Scheduler has several issues that make it less of an obvious choice, especially when there are several really good alternatives.
The age of Quartz, while an advantage, is also a disadvantage, as the Quartz API and architecture are also getting older. The API of Quartz can be considered verbose by today’s standards. This may not seem like a big deal, but it’s important for a library or language to remain attractive to the next generation of developers. Reduced verbosity is one of the main factors contributing to the popularity of Kotlin, and Java itself is moving toward becoming more beginner-friendly.
Another place where Quartz shows its age is in its architecture. When using an RDBMS, the scheduler requires the creation of more than 10 tables, which is probably overkill for most applications where the actual business logic requires fewer tables.
We have written an article that compares Quartz to a more modern solution, namely JobRunr. This article gives a feel for how complex and verbose Quartz is to use.
Performs worse than modern alternatives
When compared to more modern alternatives, Quartz is reported as having significantly lower performance. This performance issue may be caused by the use of row level locking and the complexity of the configuration making Quartz Scheduler harder to fine-tune.
Lack of built-in monitoring
Quartz Scheduler lacks an intuitive dashboard or UI for tracking and monitoring jobs. It also doesn’t provide an out-of-the-box interface with external monitoring tools like Grafana or Jaeger. Quartz users cannot actively monitor the system to proactively address issues such as job failures.
Distributed scheduling is opt-in
Quartz has the ability to handle the tasks in a distributed fashion, but this feature is opt-in. With tools like Kubernetes now allowing a pod to spin up on demand, such a feature should not be an afterthought, but rather the default.
Sporadic maintenance
The last non-beta release of Quartz dates back to October 23, 2019. While development was on hold, the ecosystem around it didn’t stop evolving. This hiatus led to a pile of unresolved issues. The users of the library are still suffering from the javax
to jakarta
namespace change, along with many bugs and security issues. They also cannot use newer Java features such as virtual threads, that may benefit background job processing, for instance to increase throughput…
Update: there is good news for Quartz users! The recent acquisition by IBM led to a spark in activity, with the community helping to fix some of the major issues. It is still unclear what this acquisition means for the future of Quartz but a new version of Quartz Scheduler - version 2.5 - was released on November 13, 2024.
Modern alternatives to Quartz Scheduler
If you’re looking for a Quartz alternative for your Java application, there are several modern open-source schedulers that offer similar features, more developer-friendly APIs, and more robust support for distributed and cloud-based environments.
We distinguish between two types of schedulers:
- The first class consists of Java job scheduling libraries. Similar to Quartz, they can be included in any Java application as a dependency. They live inside your application.
- The second class are workflow engines, which target a broader audience. These are standalone services that your application will need to communicate with.
Alternatives to Quartz in Java
There are two great alternatives to Quartz for scheduling jobs in Java, namely JobRunr and db-scheduler. They can be added as a dependency to any Java application to provide features like distributed background task processing and persisted task scheduling.
These libraries keep the number of third-party dependencies to a minimum, providing better security insurance. They are available as standard Java jars on Maven Central.
JobRunr
JobRunr is a modern, actively maintained, open-source Java library designed for background job processing. JobRunr offers an easy-to-use API that simplifies job scheduling. Unlike Quartz, JobRunr was designed with cloud-native applications in mind and provides support for distributed job scheduling.
JobRunr aims to be developer friendly by providing a simple, flexible and straightforward API, automatic retries on failure, and seamless integration with your existing infrastructure. In fact, all you need to create a background job is a Java 8 lambda or a JobRequest.
Here's a simple example of how to schedule a job using JobRunr:
// Schedule a one-off job to run in 1 hour jobScheduler.schedule( Instant.now().plus(1, ChronoUnit.HOURS), () -> sendEmail("[email protected]") );
JobRunr integrates very well with the whole Java ecosystem like Spring Boot, Quarkus and Micronaut and supports all major SQL databases and even some popular NoSQL databases.
A feature of JobRunr that neither Quartz nor db-scheduler provide out of the box is a dashboard. Thanks to the built-in dashboard, it’s easy to monitor the system to see why a job failed or to perform actions such as requeuing or deleting a job.
Used, loved and trusted by developers, the open-source version of JobRunr provides essential features you need for distributing and scheduling tasks in Java. You can expect features similar to those in Quartz Scheduler, but much easier to use. The team behind JobRunr also develops and maintains JobRunr Pro which offers Enterprise grade features, making JobRunr Pro the best job scheduling library in Java!
DB Scheduler
Another good alternative to Quartz is db-scheduler. The library was originally designed to be a simpler alternative to Quartz. This design reduces the number of required tables to one (compared to Quartz’s 11 tables!) and provides a much simpler API.
Similar to JobRunr, db-scheduler is distributed by default and guarantees that the same job will not be run concurrently. This guarantee is achieved by using the same centralized DB; in the case of db-scheduler, a relational database is typically required.
db-scheduler provides all the essential features for background job scheduling, it can handle fire-and-forget jobs as well as scheduled (a.k.a. delayed) and recurring jobs. The library provides some simple monitoring via Micrometer. It can also perform an automatic retry if a task fails.
The library is well maintained and growing in features to match the capabilities of Quartz Scheduler, without the extra complexity.
Spring Boot @Scheduled annotation
Spring Boot applications often utilize the @Scheduled
annotation for basic scheduling needs. While convenient for simple tasks, this built-in solution has limitations in distributed environments.
To address this limitation, developers can integrate ShedLock, a lightweight Java library that prevents duplicate task execution across multiple instances. Here's a simple example:
@Scheduled(cron = "0 */15 * * * *") @SchedulerLock(name = "scheduledTask") public void scheduledTask() { // Your task logic here }
While @Scheduled
with ShedLock provides a straightforward solution for distributed scheduling, it lacks some crucial features found in dedicated job scheduling solutions:
- No built-in persistence - failed tasks aren't automatically recovered if a server crashes
- Limited retry capabilities - no automatic retry mechanism for failed executions
- Basic monitoring - minimal insight into task execution status and history
For applications requiring these advanced features, consider using a dedicated job scheduling solution like those discussed above.
Other job scheduling tools
There are several job scheduling alternatives to Quartz that are aimed at a broader audience; we could probably not list them all, even if we wanted to. These alternatives come as standalone services, often referred to as workflow engines, that communicates with your application.
Using these tools means you’ll have to get used to the terminology they use. In particular, you’ll have to accept that every task, even the simplest, must be defined as a workflow.
Here we’ll briefly introduce two such workflow engines that work well with Java applications: Temporal and Kestra.
Temporal
Temporal is an open-source workflow engine designed to make applications more resilient. The engine is written in Go and can be interfaced with your Java application using the provided Java SDK.
Very similar to pure Java-based solutions like JobRunr or Quartz, Temporal provides the essential features that help developers to focus on business logic instead of worrying about the complex mechanisms behind a resilient and distributed scheduler.
In addition to providing features such as retries, scalability, delayed and recurring executions, Temporal also provides a user interface that allows you to monitor workflow execution to detect failed tasks.
Kestra
Kestra is an open-source workflow automation platform that makes job scheduling easy. The engine is written in Java but aims at running any task in any programming language. Kestra is a great low-code alternative to Quartz. It provides several hundreds of plugin allowing to extract data from any database, cloud storage, or API, and run scripts in any language.
Kestra provides a UI for writing or configuring workflows. This UI can also be used to monitor the system and track workflow state changes.
Kestra also has all the essential features required for job scheduling: reliable distributed system, retries, delayed and recurring executions, etc.
Conclusion
For a long time, there was no real alternative to Quartz for job scheduling in Java. This is no longer the case, as there are several modern tools available to developers. These tools are simpler to use while providing the essential building blocks to achieve reliable and distributed scheduling.
You may be looking for a persistent task scheduling library that integrates seamlessly into a Java application. In this case, we highly recommend trying out JobRunr. DB Scheduler is another great option.
You can also take a look at workflow engines such as Temporal or Kestra. These are especially useful if your tasks are written in different programming languages.
With these diverse tools at their disposal, Java developers can now select the one that best meets their needs, rather than relying on a single option.
References and extra resources
- Quartz Scheduler
- JobRunr
- Spring Boot
- db-scheduler
- Temporal
- Kestra
[…] Task Schedulers in Java: Modern Alternatives to Quartz Scheduler […]