总结
面试前的“练手”还是很重要的,所以开始面试之前一定要准备好啊,不然也是耽搁面试官和自己的时间。
我自己是刷了不少面试题的,所以在面试过程中才能够做到心中有数,基本上会清楚面试过程中会问到哪些知识点,高频题又有哪些,所以刷题是面试前期准备过程中非常重要的一点。
面试题及解析总结
大厂面试场景
知识点总结
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;
/**
-
@Author : JCccc
-
@CreateTime : 2020/3/21
-
@Description : 创建job实例工厂,使用默认的也许会出现spring的@Autowired 无法注入问题
**/
@Component
public class JobFactory extends AdaptableJobFactory {
@Autowired
private AutowireCapableBeanFactory beanFactory;
@Override
protected Object createJobInstance(TriggerFiredBundle bundle)
throws Exception {
Object jobInstance = super.createJobInstance(bundle);
//Job实例注入到Job工厂
beanFactory.autowireBean(jobInstance);
return jobInstance;
}
}
创建QuartzConfig.java (一些属性配置项):
import org.quartz.Scheduler;
import org.quartz.ee.servlet.QuartzInitializerListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import java.io.IOException;
import java.util.Properties;
/**
-
@Author : JCccc
-
@CreateTime : 2020/3/21
-
@Description : 调度工厂,线程池属性等等配置
**/
@Configuration
public class QuartzConfig {
@Autowired
private JobFactory jobFactory;
/**
-
调度类FactoryBean
-
@return
-
@throws IOException
*/
@Bean(“schedulerFactory”)
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
//设置调度类quartz属性
schedulerFactoryBean.setQuartzProperties(quartzProperties());
//设置jobFactory
schedulerFactoryBean.setJobFactory(jobFactory);
return schedulerFactoryBean;
}
/**
-
解析quartz.properties文件,填充属性
-
@return
-
@throws IOException
*/
@Bean
public Properties quartzProperties() throws IOException{
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
//若不做额外配置,会有默认的配置文件加载 在jar org.quartz里面 有一份quartz.properties
//propertiesFactoryBean.setLocation(new ClassPathResource(“/quartz.properties”));
propertiesFactoryBean.afterPropertiesSet();
return propertiesFactoryBean.getObject();
}
/**
-
quartz初始化监听器
-
@return
*/
@Bean
public QuartzInitializerListener initializerListener(){
return new QuartzInitializerListener();
}
/**
-
根据调度类工厂bean获取调度
-
@return
-
@throws IOException
*/
@Bean(“scheduler”)
public Scheduler scheduler() throws IOException{
return schedulerFactoryBean().getScheduler();
}
}
ps&#x