CommandLineRunner

CommandLineRunner的实现类可以在SpringBoot启动时启动(通过@Order可以控制执行顺序)
例:

@Slf4j
@Component
@Order(1)
public class StatisticReportPoolRunner implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        log.info("线程池启动");
        StatisticReportPool runnable = ApplicationContextProvider.getBean(Constants.STATISTIC_REPORT_POOL_TASK_BEAN, StatisticReportPool.class);
        new Thread(runnable).start();
    }
}

posted @ 2022-01-13 18:03  kanaliya  阅读(702)  评论(0)    收藏  举报