Setup Quartz on Heroku

There are two ways to use Quartz on Heroku:
1. Setup your own Quartz on Heroku
2. Use Heroku Quartz Addon

1. Setup your own Quartz on Heroku

Create Postgres db:
heroku addons:add heroku-postgresql:dev

Get Postgres properties:
heroku config

Use these properties to specify your:

  • org.quartz.dataSource.dataSource.URL
  • org.quartz.dataSource.dataSource.user
  • org.quartz.dataSource.dataSource.password

Your file

org.quartz.scheduler.instanceName = BatchScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.dataSource = dataSource
org.quartz.dataSource.dataSource.driver = org.postgresql.Driver
org.quartz.dataSource.dataSource.URL = jdbc:postgresql://
org.quartz.dataSource.dataSource.user = YOURUSERNAME
org.quartz.dataSource.dataSource.password = YOURPASSWORD
org.quartz.dataSource.dataSource.maxConnections = 1 

Create your Quartz tables in Postgres:
heroku pg:psql

Copy your Postgres query in the console:
Quartz tables for Quartz 2.1.6

Make sure you are using the same version of tables as specified in your pom.xml in this case my pom looks like:


2. Use Heroku Quartz Addon

Add Heroku scheduler to your project:
heroku addons:add scheduler:standard

Add the Quartz class Heroku must call in your Procfile:
scheduler: java $JAVA_OPTS -cp target/classes:target/dependency/* com.example.service.SchedulerService

Example of SchedulerService:

package com.example.service;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.repeatSecondlyForever;
import static org.quartz.TriggerBuilder.newTrigger;

public class SchedulerService {
    final static Logger logger = LoggerFactory.getLogger(SchedulerService.class);
    public static void main(String[] args) throws Exception {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        JobDetail jobDetail = newJob(DatabaseJob.class).build();
        Trigger trigger = newTrigger()
        scheduler.scheduleJob(jobDetail, trigger);

    public static class DatabaseJob implements Job {
        public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
            try {
              //Add your job that needs to execute here
            catch (Exception e) {
                logger.error(e.getMessage(), e);

One thought on “Setup Quartz on Heroku

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s