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
  • 相关阅读:
    监控kubernetes集群的方式
    Prometheus的集群与高可用
    Grafana简单用法
    Prometheus实战之配置汇总
    Leetcode Surrounded Regions
    leetcode Spiral Matrix II
    leetcode Regular Expression Matching
    leetcode Set Matrix Zeroes
    leetcode 较难题II
    Leetcode 数独
  • 原文地址:https://www.cnblogs.com/liangmm/p/12024297.html
Copyright © 2011-2022 走看看