java - Scheduling a persistent entity -


let's have db entity cronexpression field:

@entity @table(name = "job") public class job {     ...     private cronexpression cronexpression;  } 

what best approach put onto quartz schedule? use spring3 , hibernate. schedule in dao - anytime job created or updated - need schedule existed job @ application start-up..

thanks advices!

you need dao/repository cronexpression storage. create in memory dao

@repository public class jobentitydao {     public list<jobentity> findall() {         list<jobentity> list = new arraylist<jobentity>();          jobentity job1 = new jobentity("0 0 12 * * ?");         jobentity job2 = new jobentity("0 15 10 ? * *");         jobentity job3 = new jobentity("0 15 10 * * ?");          list.add(job1);         list.add(job2);         list.add(job3);          return list;     } } 

and component create quartz scheduler based on cronexpression. call quartzexecutor

@service public class quartzexecutor {       private jobentitydao jobentitydao;      @autowired      public quartzexecutor(jobentitydao jobentitydao) throws parseexception, schedulerexception {         this.jobentitydao = jobentitydao;          init();     }      @suppresswarnings({ "rawtypes", "unchecked" })     private void init() throws parseexception, schedulerexception {         list<jobentity> jobentities = jobentitydao.findall();          (jobentity jobentity : jobentities) {             system.out.println(jobentity.cronexpression);              runmetask task = new runmetask();              //specify sceduler task details             jobdetail job = new jobdetail();             job.setname("runmejob");             job.setjobclass(runmejob.class);              map datamap = job.getjobdatamap();             datamap.put("runmetask", task);              //configure scheduler time             crontrigger trigger = new crontrigger();             trigger.setname("runmejobtesting");             trigger.setcronexpression(jobentity.cronexpression);              //schedule             scheduler scheduler = new stdschedulerfactory().getscheduler();             scheduler.start();             scheduler.schedulejob(job, trigger);         }     }  } 

you can runmejob , runmetask code http://www.mkyong.com/java/quartz-scheduler-example/. know class design not good, concern try solve problem.

is looking ?


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -