https://www.jianshu.com/p/fd21fd19bb8b
http://www.cnblogs.com/liliangel/p/5531519.html
package com.lianshangche.bankroll.configuration;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
/**
*
* Description:Spring4.0编程式定时任务配置
* @author PanBaihui
* @time 2018年1月20日 下午3:55:49
*/
@Configuration
@EnableAsync
@EnableScheduling
public class SchedulingConfig implements SchedulingConfigurer{
//TaskScheduler configuration
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskExecutor());
}
/**
* 4个线程
* @return
*/
@Bean(destroyMethod="shutdown")
public Executor taskExecutor() {
return Executors.newScheduledThreadPool(4);
}
}
@Configuration
@Import({SchedulingConfig.class})
@EnableWebMvc
@ComponentScan(basePackages = {"com.pbh.web.controller"})
@EnableResponseExceptionHandler
@Lazy
public class SpringMVCConfiguration extends WebMvcConfigurerAdapter{
}