package com.blueland.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import com.blueland.config.quartz.util.ScheduleJobFactory;

/**
* @author zhengTao
* @version 创建时间：2019年4月26日 下午9:00:29
   * 容器启动时注册Quartz
*/
@Configuration
public class QuartzConfig {
	
	 @Bean
	 public ScheduleJobFactory getScheduleJobFactory() {
        return new ScheduleJobFactory();
	 }
 
	 @Bean(name = "scheduler")
	 public SchedulerFactoryBean getSchedulerFactoryBean() {
        SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
        // 注入自定义工厂类
        factoryBean.setJobFactory(getScheduleJobFactory());
        factoryBean.setQuartzProperties(quartzProperties());
        return factoryBean;
	 }

	 public Properties quartzProperties() {
        Properties properties = new Properties();
        // 默认的jobFactory
        properties.setProperty("org.quartz.scheduler.jobFactory.class", "org.quartz.simpl.SimpleJobFactory");
        // 默认的线程池
        properties.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
        // 目前线程数量
        properties.setProperty("org.quartz.threadPool.threadCount", "5");
        return properties;
	}

}
