{"record":{"id":"b214ecb193e49d85","repo":"quarkusio/quarkus","slug":"a-task-instance-cannot-be-scheduled-programmatical","errorCode":null,"errorMessage":"A task instance cannot be scheduled programmatically if DB store type is used; register a task class instead","messagePattern":"A task instance cannot be scheduled programmatically if DB store type is used; register a task class instead","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSchedulerImpl.java","lineNumber":887,"sourceCode":"\n        @Override\n        public Class<? extends SkipPredicate> skipPredicateClass() {\n            return skipPredicateClass;\n        }\n\n        @Override\n        public QuartzJobDefinition setSkipPredicate(SkipPredicate skipPredicate) {\n            if (storeType.isDbStore() && skipPredicateClass == null) {\n                throw new IllegalStateException(\n                        \"A skip predicate instance cannot be scheduled programmatically if DB store type is used; register a skip predicate class instead\");\n            }\n            return super.setSkipPredicate(skipPredicate);\n        }\n\n        @Override\n        public QuartzJobDefinition setTask(Consumer<ScheduledExecution> task, boolean runOnVirtualThread) {\n            if (storeType.isDbStore() && taskClass == null) {\n                throw new IllegalStateException(\n                        \"A task instance cannot be scheduled programmatically if DB store type is used; register a task class instead\");\n            }\n            return super.setTask(task, runOnVirtualThread);\n        }\n\n        @Override\n        public QuartzJobDefinition setAsyncTask(Function<ScheduledExecution, Uni<Void>> asyncTask) {\n            if (storeType.isDbStore() && asyncTaskClass == null) {\n                throw new IllegalStateException(\n                        \"An async task instance cannot be scheduled programmatically if DB store type is used; register an async task class instead\");\n            }\n            return super.setAsyncTask(asyncTask);\n        }\n\n        @Override\n        public Trigger schedule() {\n            checkScheduled();\n            if (task == null && asyncTask == null) {","sourceCodeStart":869,"sourceCodeEnd":905,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSchedulerImpl.java#L869-L905","documentation":"Same DB-store constraint for tasks: with `store-type=db`, a scheduled job must reference a Task class (reconstructible/serializable), not an inline Consumer instance. `setTask(Consumer, boolean)` throws IllegalStateException when a task instance is given without a task class.","triggerScenarios":"Calling `quartzJobDefinition.setTask(exec -> doWork(), false)` (or with a non-virtual-thread flag) while `store-type=db` and `setTaskClass` was not invoked.","commonSituations":"Works in dev/memory store, breaks with JDBC store; passing a method reference or lambda to setTask in production config.","solutions":["Define `class MyJob implements Consumer<ScheduledExecution>` and call `setTaskClass(MyJob.class)` instead of passing an instance","Use `quarkus.quartz.store-type=memory` if DB persistence is unnecessary","Keep an instance-free path: register the task class as a bean so Quartz can recreate it after restart"],"exampleFix":"// before\njob.setTask(this::sendReport, false);\n// after\njob.setTaskClass(SendReportTask.class); // implements Consumer<ScheduledExecution>","handlingStrategy":"validation","validationCode":"if (quarkusQuartzConfig.storeType().isDbStore()) {\n    job.setTaskClass(MyTask.class);\n} else {\n    job.setTask(this::execute, false);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always implement tasks as named Consumer<ScheduledExecution> classes","Keep a startup test that runs with store-type=db","Avoid lambdas for anything persisted by Quartz"],"tags":["quarkus","quartz","db-store","serialization"],"backgroundTag":"non-serializable-lambda","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}