Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

JDBC in cluster Job does not have grailsApplication injected correctly #6

mamsterla opened this Issue Jun 9, 2012 · 0 comments


None yet
1 participant

I have implemented a job:

import org.quartz.Job
import org.quartz.JobExecutionContext
import org.slf4j.LoggerFactory
import org.slf4j.Logger


  • Created with IntelliJ IDEA.

  • User: mamster

  • Date: 6/8/12

  • Time: 8:29 PM
    public class PopularImageJob implements Job {

    private static Logger log = LoggerFactory.getLogger(PopularImageJob.class);

    def grailsApplication
    def imageService

    public PopularImageJob() {}

    void execute(JobExecutionContext jobExecutionContext) {
    log.info("Called job: ${jobExecutionContext.jobDetail.key.name} - grailsApplication = ${grailsApplication} imageService = ${imageService} jobExecutionContext = ${jobExecutionContext.dump()}")
    assert grailsApplication != null


This is registered in Config.groovy like this:

'''grails.plugin.quartz2.autostartup = true
org {
quartz {
jdbcStore = true
waitForJobsToCompleteOnShutdown = true
overwriteExistingJobs = true
jobStore.misfireThreshold = 60000
jobStore.class = 'org.quartz.impl.jdbcjobstore.JobStoreTX'
jobStore.driverDelegateClass = 'org.quartz.impl.jdbcjobstore.StdJDBCDelegate'
jobStore.useProperties = false
jobStore.tablePrefix = QRTZ_
jobStore.isClustered = true
jobStore.clusterCheckinInterval = 5000
plugin.shutdownhook.class = 'org.quartz.plugins.management.ShutdownHookPlugin'
plugin.shutdownhook.cleanShutdown = true
grails.plugin.quartz2.jobSetup.job1 = { quartzScheduler, ctx ->
// define the job and tie it to our HelloJob class
def map = [name:"popularImageJob",jobClass:PopularImageJob.class, concurrent:false, jobData:[gormSession:true] ]
JobDetail jobDetail = new SimpleJobDetail(map)
jobDetail.concurrentExectionDisallowed = true

    // Trigger the job to run now, and then every 40 seconds
    Trigger trigger = new SimpleTriggerImpl(name:"popularImageTrigger", startTime:new Date(),repeatInterval:300000,repeatCount:-1)
    // Tell quartz to schedule the job using our trigger
    quartzScheduler.scheduleJob(jobDetail, trigger);


I see the job running correctly, but the assertion of grailsApplication != null fails.
If I take the same job and run it with a RAMJobStore, it works as expected injecting the grailsApplication

At the same time, you cannot use the other mechanism since the service is not serializable in the JobDataMap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment