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
  • 相关阅读:
    css实现多行文本溢出显示省略号(…)全攻略
    Git使用教程
    requireJS对文件合并与压缩(二)
    requireJS(版本是2.1.15)学习教程(一)
    谷歌浏览器javascript调试教程
    IPMITool driver
    ironic的自动化脚本
    serial console
    如何将自己写的代码上传到github上
    硬件检查
  • 原文地址:https://www.cnblogs.com/liangmm/p/12024297.html
Copyright © 2011-2022 走看看