spring动态创建定时任务 @Component("schedulerListener")public class SchedulerListener implements ApplicationListener { private static final Logger logger = Logger.getLogger(SchedulerListener.class); private static ThreadPoolTaskSched
@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"); } }