Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. @Configuration
  2. @EnableBatchProcessing
  3. public class QuartzSpringConfiguration {
  4.  
  5. @Bean
  6. public JobDetailFactoryBean jobDetailFactoryBean(){
  7. JobDetailFactoryBean factory = new JobDetailFactoryBean();
  8. factory.setJobClass(UpdateStatusJob.class);
  9. return factory;
  10. }
  11.  
  12. @Bean
  13. public SimpleTriggerFactoryBean simpleTriggerFactoryBean(){
  14. SimpleTriggerFactoryBean stFactory = new SimpleTriggerFactoryBean();
  15. stFactory.setJobDetail(jobDetailFactoryBean().getObject());
  16. stFactory.setStartDelay(3000);
  17. stFactory.setRepeatInterval(30000);
  18. return stFactory;
  19. }
  20.  
  21. @Bean
  22. public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
  23. SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
  24. scheduler.setTriggers(simpleTriggerFactoryBean().getObject());
  25. scheduler.setJobFactory(jobFactory());
  26. return scheduler;
  27. }
  28.  
  29. @Bean
  30. public JobFactory jobFactory() {
  31. return new AutowiringSpringBeanJobFactory();
  32. }
  33.  
  34. @Bean
  35. public Properties quartzProperties() throws IOException {
  36. PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
  37. propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
  38. propertiesFactoryBean.afterPropertiesSet();
  39. return propertiesFactoryBean.getObject();
  40. }
  41. }
  42.  
  43. #scheduler name will be "MyScheduler"
  44. org.quartz.scheduler.instanceName = MyScheduler
  45.  
  46. #All of Quartz data is held in memory (rather than in a database).
  47. org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
  48.  
  49. @Component
  50. public class UpdateStatusJob extends QuartzJobBean {
  51.  
  52. private static Logger logger = LogManager.getLogger(UpdateStatusJob.class.getName());
  53.  
  54. private TaskRepository taskRepository;
  55.  
  56. /*
  57. * UpdateStatusJob(TaskRepository taskRepository) throws
  58. * JobExecutionException{ this.taskRepository= taskRepository; }
  59. */
  60.  
  61. @Autowired
  62. public void setTaskRepository(TaskRepository taskRepository) {
  63. this.taskRepository = taskRepository;
  64. }
  65.  
  66. @Override
  67. protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
  68.  
  69. Iterator<Tasks> itr=taskRepository.findAll().iterator();
  70.  
  71. while(itr.hasNext()){
  72. logger.debug("task :"+itr.next());
  73. }
  74.  
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement