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
  • 相关阅读:
    用免费Scrum工具Leangoo思维导图 实现影响地图
    mysql-线程模型
    mongodb-锁
    mongodb-mmapv1存储引擎解析(转)
    netty-read
    netty-bind
    netty-eventloop
    java基础-Executor
    ehcache3-源码简析三
    ehcache3-源码简析二
  • 原文地址:https://www.cnblogs.com/liangmm/p/12024297.html
Copyright © 2011-2022 走看看