zoukankan      html  css  js  c++  java
  • Spring Schedule定时任务多线程执行任务配置

    @Configuration
    public class ScheduleConfig implements SchedulingConfigurer {
        @Override
        public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
            Method[] methods = BatchProperties.Job.class.getMethods();
            int defaultPoolSize = 10;
            int corePoolSize = 0;
            if (methods != null && methods.length > 0) {
                for (Method method : methods) {
                    Scheduled annotation = method.getAnnotation(Scheduled.class);
                    if (annotation != null) {
                        corePoolSize++;
                    }
                }
                if (defaultPoolSize > corePoolSize)
                    corePoolSize = defaultPoolSize;
            }
            taskRegistrar.setScheduler(Executors.newScheduledThreadPool(corePoolSize));
        }
    }
    @Configuration
    public class ScheduleConfig implements SchedulingConfigurer {
        @Override
        public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
            Method[] methods = BatchProperties.Job.class.getMethods();
            int defaultPoolSize = 10;
            int corePoolSize = 0;
            if (methods != null && methods.length > 0) {
                for (Method method : methods) {
                    Scheduled annotation = method.getAnnotation(Scheduled.class);
                    if (annotation != null) {
                        corePoolSize++;
                    }
                }
                if (defaultPoolSize > corePoolSize)
                    corePoolSize = defaultPoolSize;
            }
            taskRegistrar.setScheduler(Executors.newScheduledThreadPool(corePoolSize));
        }
    }
    @EnableScheduling
  • 相关阅读:
    在Ubuntu_meta 16.04中设置默认Python3.5的命令
    树莓派安装中文输入法Fcitx及Google拼音输入法
    树莓派安装ubuntu_meta并配置开发环境
    业务代表模式
    MVC 模式
    访问者模式
    模板模式
    Linux进程调度与抢占
    IP地址
    策略模式
  • 原文地址:https://www.cnblogs.com/liangmm/p/12024297.html
Copyright © 2011-2022 走看看