how to schedule a quartz job with scala -
i trying simple example of quartz job running in scala.
configure() gets executed once when module loaded.
lazy val quartz = stdschedulerfactory.getdefaultscheduler override def configure() = { val job = new job { override def execute(jobexecutioncontext: jobexecutioncontext) = { println("event") } } val job = jobbuilder.newjob(job.getclass) .withidentity("job", "group") .build val trigger: trigger = triggerbuilder .newtrigger .withidentity("trigger", "group") .withschedule( cronschedulebuilder.cronschedule("0/5 * * * * ?")) .build quartz.start quartz.schedulejob(job, trigger) }
however, error message when code runs.
2015-09-29 15:27:05,015 [defaultquartzscheduler_quartzschedulerthread] error org.quartz.core.errorlogger - error occured instantiating job executed. job= 'group.job' org.quartz.schedulerexception: problem instantiating class 'com.search.binder.searchmodule$$anon$1' @ org.quartz.simpl.simplejobfactory.newjob(simplejobfactory.java:58) ~[quartz-2.2.1.jar:na] @ org.quartz.simpl.propertysettingjobfactory.newjob(propertysettingjobfactory.java:69) ~[quartz-2.2.1.jar:na] @ org.quartz.core.jobrunshell.initialize(jobrunshell.java:127) ~[quartz-2.2.1.jar:na] @ org.quartz.core.quartzschedulerthread.run(quartzschedulerthread.java:375) [quartz-2.2.1.jar:na] caused by: java.lang.instantiationexception: com.search.binder.searchmodule$$anon$1 @ java.lang.class.newinstance(class.java:427) ~[na:1.8.0_45] @ org.quartz.simpl.simplejobfactory.newjob(simplejobfactory.java:56) ~[quartz-2.2.1.jar:na] ... 3 common frames omitted caused by: java.lang.nosuchmethodexception: com.search.binder.searchmodule$$anon$1.<init>() @ java.lang.class.getconstructor0(class.java:3082) ~[na:1.8.0_45] @ java.lang.class.newinstance(class.java:412) ~[na:1.8.0_45] ... 4 common frames omitted
does have "as simple possible" example of quartz scheduler running in scala?
i think problem quartz trying instantiate new instance of job
can't find constructor because class passing via job.getclass
anonymous class. try defining follows:
class myjob extends job { override def execute(jobexecutioncontext: jobexecutioncontext) = { println("event") } }
and then:
val job = jobbuilder.newjob(classof[myjob]) .withidentity("job", "group") .build
Comments
Post a Comment