当前位置 : 主页 > 编程语言 > c++ >

spring动态创建定时任务

来源:互联网 收集:自由互联 发布时间:2021-06-30
spring动态创建定时任务 @Component("schedulerListener")public class SchedulerListener implements ApplicationListener { private static final Logger logger = Logger.getLogger(SchedulerListener.class); private static ThreadPoolTaskSched
spring动态创建定时任务
@Component("schedulerListener")
public class SchedulerListener implements ApplicationListener
 
   {
    private static final Logger logger = Logger.getLogger(SchedulerListener.class);

    private static ThreadPoolTaskScheduler tts = null;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (tts == null) {
            tts = new ThreadPoolTaskScheduler();
            tts.initialize();
        }
        tts.schedule(new TestRunnable(), new CronTrigger("0 20 0 * * *"));
    }
}

public class TestRunnable implements Runnable {
    @Override
    public void run() {
        System.out.println("hello");
    }
}
 
网友评论