Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Describe the main concepts of Quartz (Job, JobDetail, Trigger, Scheduler) and how Spring Boot's spring-boot-starter-quartz wires them.

In Quartz, a Job is the code that runs, through execute(JobExecutionContext); a JobDetail describes one named instance of that job with its JobDataMap of settings; a Trigger says when it fires, with SimpleTrigger for intervals and CronTrigger for cron expressions; and the Scheduler fires triggers using a thread pool and a job store, in memory or in a database. spring-boot-starter-quartz auto-configures the Scheduler, registers every JobDetail and Trigger bean with it, lets jobs use Spring dependency injection, and switches to a database store with spring.quartz.job-store-type=jdbc.

Why this question is asked

@Scheduled covers simple cases, but as soon as we need schedules that survive restarts, many jobs shared across instances, or rules for runs missed during downtime, we reach for Quartz. Its vocabulary confuses people at first, because the job, its description and its schedule are three separate objects. Interviewers ask this question to check that we understand that separation and how Spring Boot fits Quartz into an application. In this answer, we will go through each Quartz concept with the reason it exists, write a job with its JobDetail and Trigger as Spring beans, see what the Boot starter configures for us, and switch the job store to JDBC.

1Job: The Code That Runs

A Job is a class that implements org.quartz.Job, which has one method: void execute(JobExecutionContext context) throws JobExecutionException. The context gives the job everything about this particular firing: the JobDetail, the trigger that fired, the scheduled and actual fire times, and the merged data map.

One thing surprises people: Quartz creates a new instance of the job class for every execution, through a job factory. So a job should not keep state in its fields between runs. State that must survive between runs goes into the JobDataMap with @PersistJobDataAfterExecution, or better, into our own database.

2JobDetail and JobDataMap: A Named Instance of a Job

The same job class can be scheduled several times with different settings. Each of these is a JobDetail: it has a key (a name and a group), the job class, a durability flag, and a JobDataMap, a map of settings for that instance. For example, one ReportJob class could have two JobDetails, report-eu and report-us, each with a different region in its data map.

Separating the description from the class is what makes persistence possible. In a database store, Quartz saves the JobDetail as a row, class name and data map included, and recreates the job instance from it when a trigger fires, even after a restart.

3Trigger: When It Fires

A Trigger is attached to one JobDetail and says when it fires. A SimpleTrigger fires at a start time and then repeats at a fixed interval, a given number of times or forever: 'every 5 minutes'. A CronTrigger fires on a cron expression: 'at 06:00 on weekdays'. A JobDetail can have several triggers, for example a weekday cron and a separate one-off trigger for a rerun.

Triggers also carry the misfire instruction, which says what to do if the trigger could not fire at its time, for example because the scheduler was down, and they can have a priority and a calendar that excludes dates such as holidays. Quartz cron expressions differ slightly from Spring's: they need a ? in either the day-of-month or the day-of-week field, and they allow an optional seventh field for the year.

4Scheduler: The Engine

The Scheduler is the engine that holds everything together. It keeps the triggers in a job store, wakes up when the next trigger is due, and hands the firing to a worker thread from its thread pool, where the job factory creates the job and calls execute. By default the pool has 10 threads, so up to 10 jobs run at once.

The job store decides persistence. RAMJobStore keeps everything in memory, which is fast but forgets all schedules and their state on restart. The JDBC job store keeps them in database tables, the QRTZ_ tables, which survive restarts and, in clustered mode, are shared by several application instances.

Step throughQuartz inside a Spring Boot application
  1. Schedulercreated by SchedulerFactoryBean, started with the application
  2. TriggersSimpleTrigger and CronTrigger beans, each pointing at a JobDetail
  3. JobDetailsnamed job instances with their JobDataMap
  4. Thread pool and job factory10 threads by default; the factory creates jobs with Spring injection
  5. Job storeRAMJobStore by default, JDBC job store with the QRTZ tables

5 layers, from the top down. Step through them one at a time.

Spring Boot builds all of these from properties and our JobDetail and Trigger beans.

5Wiring It in Spring Boot

With spring-boot-starter-quartz on the classpath, Spring Boot creates and starts a Scheduler through Spring's SchedulerFactoryBean. Any JobDetail, Trigger and Calendar beans in the context are registered with it automatically. The job factory it configures creates each job instance through Spring, so the job can have dependencies injected, and JobDataMap entries are applied to matching setters.

Java
public class ReportJob extends QuartzJobBean { // Spring's convenience base class for Job
private final ReportService reports; // injected by Spring
private String region; // set from the JobDataMap
public ReportJob(ReportService reports) { this.reports = reports; }
public void setRegion(String region) { this.region = region; }
@Override
protected void executeInternal(JobExecutionContext ctx) {
reports.build(region, ctx.getScheduledFireTime()); // region = "EU"
}
}
@Configuration
class QuartzJobsConfig {
@Bean
JobDetail reportEuDetail() {
return JobBuilder.newJob(ReportJob.class)
.withIdentity("report-eu", "reports")
.usingJobData("region", "EU")
.storeDurably() // keep the JobDetail even without a trigger
.build();
}
@Bean
Trigger reportEuTrigger(JobDetail reportEuDetail) {
return TriggerBuilder.newTrigger()
.forJob(reportEuDetail)
.withIdentity("report-eu-weekdays", "reports")
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 6 ? * MON-FRI")
.inTimeZone(TimeZone.getTimeZone("Europe/Berlin")))
.build();
}
}
// 06:00 Berlin time on weekdays: ReportJob created, region injected, executeInternal called

Notice the ? in the day-of-month field of the Quartz cron expression, and the explicit time zone. A SimpleTrigger is built the same way with SimpleScheduleBuilder.simpleSchedule().withIntervalInMinutes(5).repeatForever().

6Switching to the JDBC Job Store

The in-memory store is the default. For schedules that survive restarts, and for clustering, we set the store type to jdbc. Spring Boot then uses the application's DataSource, and can create the QRTZ_ tables at startup.

Properties
spring.quartz.job-store-type=jdbc
spring.quartz.jdbc.initialize-schema=never # tables created by our Flyway migration instead
spring.quartz.overwrite-existing-jobs=true # update stored JobDetails from the beans on startup
spring.quartz.properties.org.quartz.jobStore.isClustered=true
spring.quartz.properties.org.quartz.threadPool.threadCount=5

Every Quartz property can be passed through spring.quartz.properties. In production most teams create the tables with their migration tool from the scripts that ship with Quartz, rather than letting the application create them, so that schema changes are reviewed like any other. overwrite-existing-jobs matters with a JDBC store: without it, a JobDetail already stored in the database is not updated when we change the bean, which surprises people after a deployment.

7Follow-up questions

Why are JobDetail and Trigger separate objects?

Because one job can have many schedules and a schedule can change without changing the job. Keeping them apart lets us add a rerun trigger, pause one trigger, or change a cron expression while the JobDetail, its data and its history stay the same.

Can a Quartz job use @Transactional?

Not directly on the job instance, because Quartz creates a new instance per run and it is not a Spring proxy. The usual pattern is to keep the job thin and call a Spring service bean whose methods are @Transactional, which also makes the logic easy to test without Quartz.

When is Quartz better than @Scheduled?

When schedules must survive restarts, when missed runs need explicit misfire rules, when jobs must be spread across instances with one firing per trigger, or when schedules are created at runtime, for example a report per customer. For a few fixed in-memory tasks, @Scheduled is simpler.

8Conclusion

In this answer, we saw Quartz's four core ideas: a Job with execute(JobExecutionContext), created anew for each run; a JobDetail that names one instance of a job and carries its JobDataMap; Triggers, SimpleTrigger for intervals and CronTrigger for cron, that say when it fires; and the Scheduler that fires triggers with a thread pool and a RAM or JDBC job store. Spring Boot's starter creates the Scheduler, registers JobDetail and Trigger beans, injects dependencies into jobs, and moves storage to the database with spring.quartz.job-store-type=jdbc.

What to say in the interviewAbout 80 seconds aloud

Open with

Quartz separates what runs from when it runs. A Job is the class with execute taking a JobExecutionContext, and Quartz creates a new instance for every run, so jobs shouldn't keep state in fields.

Then, if they want more

A JobDetail is a named instance of a job, a key, the class and a JobDataMap of settings, so the same class can be scheduled twice with different data.

A Trigger says when a JobDetail fires: a SimpleTrigger for a start time and a repeat interval, or a CronTrigger for a cron expression, which in Quartz needs a question mark in one of the day fields. Triggers also carry the misfire instruction.

The Scheduler is the engine that holds the triggers in a job store, RAM by default or JDBC with the QRTZ tables, and runs jobs on its thread pool, ten threads by default.

With spring-boot-starter-quartz, Boot creates and starts the Scheduler, registers every JobDetail and Trigger bean automatically, and creates jobs through Spring, so they get dependency injection and data map values on setters; extending QuartzJobBean is convenient. Setting spring.quartz.job-store-type to jdbc puts everything in the database, which is needed for persistence and clustering.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Batch reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Describe the main concepts of Quartz (Job, JobDetail, Trigger, Scheduler) and how Spring...": https://scrivio-interview-library.netlify.app/spring-boot/scheduling/a7747f7899/