{"record":{"id":"7b8d9604d289049b","repo":"quarkusio/quarkus","slug":"an-async-task-instance-cannot-be-scheduled-program","errorCode":null,"errorMessage":"An async task instance cannot be scheduled programmatically if DB store type is used; register an async task class instead","messagePattern":"An async task instance cannot be scheduled programmatically if DB store type is used; register an async 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":896,"sourceCode":"                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) {\n                throw new IllegalStateException(\"Either sync or async task must be set\");\n            }\n            scheduled = true;\n            SyntheticScheduled scheduled = new SyntheticScheduled(identity, cron, every, 0, TimeUnit.MINUTES, delayed,\n                    overdueGracePeriod, concurrentExecution, skipPredicate, timeZone, implementation, executionMaxDelay,\n                    description);\n            return createJobDefinitionQuartzTrigger(this, scheduled, null);\n        }\n","sourceCodeStart":878,"sourceCodeEnd":914,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSchedulerImpl.java#L878-L914","documentation":"For async tasks the DB store demands a Function class, not an instance: `setAsyncTask(Function)` throws IllegalStateException when a lambda/instance is supplied while `store-type=db` and `setAsyncTaskClass` was not called.","triggerScenarios":"Calling `quartzJobDefinition.setAsyncTask(exec -> Uni.createFrom().voidItem())` with DB store and no async task class registered.","commonSituations":"Reactive scheduled jobs written with lambdas that worked with in-memory store; JDBC store enabled via config change, breaking existing programmatic schedules at startup.","solutions":["Create a class implementing `Function<ScheduledExecution, Uni<Void>>` and register it with `setAsyncTaskClass(MyAsyncTask.class)`","Change store type to memory when persistence is not required","Review all programmatic jobs after switching store-type to db and convert lambdas to classes"],"exampleFix":"// before\njob.setAsyncTask(ctx -> refreshCache());\n// after\njob.setAsyncTaskClass(RefreshCacheTask.class); // implements Function<ScheduledExecution, Uni<Void>>","handlingStrategy":"validation","validationCode":"if (quarkusQuartzConfig.storeType().isDbStore()) {\n    job.setAsyncTaskClass(MyAsyncTask.class);\n} else {\n    job.setAsyncTask(ctx -> runAsync(ctx));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Implement async tasks as named Function classes","Add an integration test enabling JDBC store","Review job builders whenever store type changes"],"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-12T22:17:10.623Z"}