Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableBatchProcessing
- public class QuartzSpringConfiguration {
- @Bean
- public JobDetailFactoryBean jobDetailFactoryBean(){
- JobDetailFactoryBean factory = new JobDetailFactoryBean();
- factory.setJobClass(UpdateStatusJob.class);
- return factory;
- }
- @Bean
- public SimpleTriggerFactoryBean simpleTriggerFactoryBean(){
- SimpleTriggerFactoryBean stFactory = new SimpleTriggerFactoryBean();
- stFactory.setJobDetail(jobDetailFactoryBean().getObject());
- stFactory.setStartDelay(3000);
- stFactory.setRepeatInterval(30000);
- return stFactory;
- }
- @Bean
- public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
- SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
- scheduler.setTriggers(simpleTriggerFactoryBean().getObject());
- scheduler.setJobFactory(jobFactory());
- return scheduler;
- }
- @Bean
- public JobFactory jobFactory() {
- return new AutowiringSpringBeanJobFactory();
- }
- @Bean
- public Properties quartzProperties() throws IOException {
- PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
- propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
- propertiesFactoryBean.afterPropertiesSet();
- return propertiesFactoryBean.getObject();
- }
- }
- #scheduler name will be "MyScheduler"
- org.quartz.scheduler.instanceName = MyScheduler
- #All of Quartz data is held in memory (rather than in a database).
- org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
- @Component
- public class UpdateStatusJob extends QuartzJobBean {
- private static Logger logger = LogManager.getLogger(UpdateStatusJob.class.getName());
- private TaskRepository taskRepository;
- /*
- * UpdateStatusJob(TaskRepository taskRepository) throws
- * JobExecutionException{ this.taskRepository= taskRepository; }
- */
- @Autowired
- public void setTaskRepository(TaskRepository taskRepository) {
- this.taskRepository = taskRepository;
- }
- @Override
- protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
- Iterator<Tasks> itr=taskRepository.findAll().iterator();
- while(itr.hasNext()){
- logger.debug("task :"+itr.next());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement