i have problem quartz ( plugin :quartz2:2.1.6.2 have test plugin :quartz:1.0-rc7 problem not change) on grails project ( grails 2.2.1 ).
i have job this
class myjob { def concurrent = false def execute(context){ try { //.... // works domains ..... mydomain.save(flush: true) // works domains ..... //.... sessionfactory.currentsession.flush() } catch (org.springframework.dao.optimisticlockingfailureexception olfe) { println "job failed database exception " } catch ( org.springframework.orm.hibernate3.hibernateoptimisticlockingfailureexception ole){ println "job failed database exception " } catch ( org.hibernate.hibernateexception hibe ){ println "job failed database exception " } } } }
sometimes staleobjectstateexception occour in execute method. ok logic, i'm using grails optimistic locking , exceptions occour once week.
the problem when exceptions occour job stops fire again.
i have tried co wrap method code in try catch , flush hibernate session inside capture exception without fortune. exception not capture of catchs.
looking online found old grails quartz bug it's fixed, , in case using try{}catch must bypass bug.
p.s. job scheduled bootstrab call of type
myjob.schedule( 10000l )
the exception stops scheduling
[194949896] core.errorlogger unable notify joblistener(s) of job executed: (error ignored). trigger= default.mt_3tbn6lewgiqa3 job= default.myjob org.quartz.schedulerexception: joblistener 'persistencecontextjoblistener' threw exception: row updated or deleted transaction (or unsaved-value mapping incorrect): [mydomain#42] [see nested exception: org.hibernate.staleobjectstateexception: row updated or deleted transaction (or unsaved-value mapping incorrect): [mydomain#42]] @ org.quartz.core.quartzscheduler.notifyjoblistenerswasexecuted(quartzscheduler.java:1939) @ org.quartz.core.jobrunshell.notifyjoblistenerscomplete(jobrunshell.java:361) @ org.quartz.core.jobrunshell.run(jobrunshell.java:235) @ org.quartz.simpl.simplethreadpool$workerthread.run(simplethreadpool.java:557) caused by: org.hibernate.staleobjectstateexception: row updated or deleted transaction (or unsaved-value mapping incorrect): [mydomain#42] @ grails.plugin.quartz2.persistencecontextjoblistener.jobwasexecuted(persistencecontextjoblistener.groovy:46) @ org.quartz.core.quartzscheduler.notifyjoblistenerswasexecuted(quartzscheduler.java:1937) ... 3 more ..... events.patcheddefaultflusheventlistener not synchronize database state session org.hibernate.staleobjectstateexception: row updated or deleted transaction (or unsaved-value mapping incorrect): [myjob#42] @ myjob.execute(myjob.groovy:354) @ grails.plugin.quartz2.grailsartefactjob.execute(grailsartefactjob.java:57) @ org.quartz.core.jobrunshell.run(jobrunshell.java:213) @ org.quartz.simpl.simplethreadpool$workerthread.run(simplethreadpool.java:557)
i apologize reviving old post, encountered issue legacy grails app (grails 2.2.3) , flushing session in execute method did not solve issue i'll outline did fix problem.
in our case, exception happen outside context of execute method, when explicitly flushed session within execute method. more specifically, exception thrown within quartz2 plugin's persistencecontextjoblistener code flushes session after execute method finished executing. after reviewing quartz2 plugin code realized that needed override default persistencecontextjoblistener wraps job execute method , flushes session.
first, notice there's no exception handling within jobwasexecuted callback method of persistencecontextjoblistener.
all need implement own job listener , wrap jobwasexecuted code in try/catch. see following code snippets example of how this.
https://gist.github.com/jmiranda/45084eb32f07f6e3d1934547cd4fbb9f https://gist.github.com/jmiranda/5148f0a67afc8950bad950793e9c2303
we used original quartz plugin's sessionbinderjoblistener example (err, more or less copied it).
anyway, should point preventing triggered jobs stopping altogether due uncaught staleobjectstateexception.
Comments
Post a Comment