分布式调度器

1.Spring Task

Spring Task 是 Spring 框架的一个组件,它为任务调度提供了支持,使得开发者能够创建后台任务或定期执行的任务。通过 Spring Task,您可以方便地在 Java 应用程序中实现定时任务,比如每天凌晨进行数据同步、每小时执行一次清理操作等。

1.1 配置类启用定时任务支持

启动类添加@EnableScheduling注解,,以开启基于注解的任务调度器。

@SpringBootApplication
@EnableAsync//支持异步的注解
@EnableScheduling
@Slf4j
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
         log.debug("容器启动");
    }

}

1.2 同步定时任务

创建一个服务类或组件,在其中的方法上使用 @Scheduled 注解来定义定时任务。例如

@Component
@Slf4j
public class Task {

   // @Scheduled(fixedDelay = 5000)//上次结束到下一次开始间隔为5秒
    public void Task1(){
      log.debug("开始执行Task1");
        ThreadUtil.safeSleep(8*1000);
    }

   // @Scheduled(fixedRate = 5000)//上一次开始执行时间和下一次开始时间间隔为5秒,若睡眠时间小于间隔时间,则每5秒执行一次,如大于间隔时间,则按照
    //间隔时间来执行
    public void Task2(){
        log.debug("开始执行Task2");
        ThreadUtil.safeSleep(1000);
        //ThreadUtil.safeSleep(10*1000);
    }

    //@Scheduled(initialDelay = 5000,fixedDelay = 10*1000)//第一次延迟5秒后执行,之后按照每10秒执行一次
    public void Task3(){
        log.debug("开始执行Task3");

        //ThreadUtil.safeSleep(10*1000);
    }

    // @Scheduled(fixedDelay = 5000)//上次结束到下一次开始间隔为5秒
    // @Async //开启异步线程,与启动类的@EnableAsync连用
    public void Task4(){
        log.debug("开始执行Task4");
        ThreadUtil.safeSleep(8*1000);
    }

   // @Scheduled(fixedDelay = 200)//上次结束到下一次开始间隔为5秒
   // @Async //开启异步线程,与启动类的@EnableAsync连用
    public void Task5(){
        log.debug("开始执行Task5");
        ThreadUtil.safeSleep(8*1000);
    }

 //@Scheduled(cron = "0/1 * * * * ? ")//上次结束到下一次开始间隔为5秒
   @Async //开启异步线程,与启动类的@EnableAsync连用
    public void Task6(){
        log.debug("开始执行Task6");
      ThreadUtil.safeSleep(8*1000);
    }
   // @Scheduled(fixedRate = 200)//上一次开始执行时间和下一次开始时间间隔为5秒,若睡眠时间小于间隔时间,则每5秒执行一次,如大于间隔时间,则按照
   // @Async
    //间隔时间来执行
    public void Task7(){
        log.debug("开始执行Task7");
        ThreadUtil.safeSleep(5000);
       ThreadUtil.safeSleep(10*1000);
    }


}

在 Spring Task 中,当我们使用 @Scheduled 注解来定义定时任务时,默认会使用一个单线程的 ScheduledTaskExecutor 来按顺序执行这些任务。这意味着,如果不自定义线程池配置,那么多个定时任务将会按照它们被触发的顺序依次执行,而不是并行执行。

若要改变这种行为,使得定时任务能够并发执行,可以通过配置 ThreadPoolTaskSchedulerThreadPoolTaskExecutor 来创建一个拥有多个工作线程的线程池。这样,不同的定时任务就可以在各自独立的线程中同时运行,提高系统整体的处理效率。

1.3 异步定时任务

  1. 开启异步支持: 要在 Spring Boot 应用中启用异步方法调用,需在启动类上添加 @EnableAsync 注解。

2.定义异步方法: 在服务类中定义一个方法,并使用 @Async 注解标记它以实现异步执行:

默认情况下,Spring Boot 会配置一个简单的异步任务执行器。但你可能需要调整其配置,如核心线程数、队列容量、最大线程数等. 例如:


#配置日志
logging.level.root = error
logging.level.com.by = debug


#配置异步线程任务
# Spring Task 调度线程池大小,默认为 1,建议根据任务量进行调整。
# 如果不开启异步,可以理解为工厂经理们亲自处理任务
spring.task.scheduling.pool.size=10
# 调度线程名称前缀,默认为 "scheduling-"
spring.task.scheduling.thread-name-prefix=jingli-

# 任务执行线程池配置
# 核心线程池大小,默认为 8
spring.task.execution.pool.core-size=4
# 线程池最大数量,根据实际任务需求进行定制
spring.task.execution.pool.max-size=6
# 线程空闲等待时间,默认为 60 秒
spring.task.execution.pool.keep-alive=60s
#配置执行线程的名称,默认为task
spring.task.execution.thread-name-prefix=worker-
#工作队列,默认Integer,MAX_VALUE,21亿
spring.task.execution.pool.queue-capacity=2

spring.task.scheduling.pool 和 spring.task.execution.pool 区别:

在 Spring Boot 中,spring.task.scheduling.poolspring.task.execution.pool 分别对应着两种不同的线程池配置,分别服务于不同的目的:

spring.task.scheduling.pool: 这个配置是针对 Spring Task 的定时任务调度器 ThreadPoolTaskScheduler。当应用中使用 @Scheduled 注解来定义和执行定时任务时,这个线程池负责调度和执行这些定时任务。配置这个线程池的大小(如 size 属性),意味着你可以控制并发执行定时任务的线程数量,以此来优化系统资源利用,特别是在有多项定时任务需要并行执行时。

spring.task.execution.pool: 这个配置是针对 Spring 异步任务执行器 ThreadPoolTaskExecutor。当应用中使用 @Async 注解来标记某个方法以异步方式执行时,这个线程池会被用来执行那些被异步调用的方法。配置这个线程池的核心线程数(core-size)、最大线程数(max-size)以及线程空闲存活时间(keep-alive)等属性,可以帮助你管理和控制异步任务执行时的并发级别和资源利用率。

总结来说,spring.task.scheduling.pool 主要是用于管理定时任务的并发执行,而 spring.task.execution.pool 则是处理程序中通过异步注解触发的非定时异步任务的并发执行。两者都是为了提高系统处理能力和响应速度,但是应用场景有所不同。

1.4 Api说明

1. fixedDelay :上次结束到下次开始执行时间间隔:

@Scheduled(fixedDelay = 4000) 

 

2. fixedRate:上一次开始执行时间和下次开始时间间隔10s。如:

@Scheduled(fixedRate = 10000) 

 

3. initialDelay:第一次延迟多长时间后再执行。

@Scheduled(initialDelay=1000, fixedRate=5000) //第一次延迟1秒后执行,之后按fixedRate的规则每5秒执行一次

4. cron 

2.分布式调度平台

2.1.xxl-job介绍

xxl-job 是一个轻量级分布式任务调度框架,支持动态添加、修改、删除定时任务,支持海量任务分片执行,支持任务执行日志在线查看和分页查询,同时支持任务失败告警和重试机制,支持分布式部署和高可用。xxl-job 的核心思想是将任务的调度和执行分离,通过调度中心统一控制任务的分配和执行,实现任务的统一管理和调度。xxl-job 可以轻松集成到 Spring、Spring Boot、Dubbo 等主流框架中,使用简单方便,已经广泛应用于各大互联网公司的生产环境中。

xuxueli.com/xxl-job/

2.2.安装-调度器

2.2.1 初始化“调度数据库”



# XXL-JOB v2.4.0-SNAPSHOT
# Copyright (c) 2015-present, xuxueli.

CREATE database if NOT EXISTS `xxl_job` default character set utf8mb4 collate utf8mb4_unicode_ci;
use `xxl_job`;

SET NAMES utf8mb4;

CREATE TABLE `xxl_job_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT '执行器主键ID',
  `job_desc` varchar(255) NOT NULL,
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  `author` varchar(64) DEFAULT NULL COMMENT '作者',
  `alarm_email` varchar(255) DEFAULT NULL COMMENT '报警邮件',
  `schedule_type` varchar(50) NOT NULL DEFAULT 'NONE' COMMENT '调度类型',
  `schedule_conf` varchar(128) DEFAULT NULL COMMENT '调度配置,值含义取决于调度类型',
  `misfire_strategy` varchar(50) NOT NULL DEFAULT 'DO_NOTHING' COMMENT '调度过期策略',
  `executor_route_strategy` varchar(50) DEFAULT NULL COMMENT '执行器路由策略',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
  `executor_block_strategy` varchar(50) DEFAULT NULL COMMENT '阻塞处理策略',
  `executor_timeout` int(11) NOT NULL DEFAULT '0' COMMENT '任务执行超时时间,单位秒',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
  `glue_type` varchar(50) NOT NULL COMMENT 'GLUE类型',
  `glue_source` mediumtext COMMENT 'GLUE源代码',
  `glue_remark` varchar(128) DEFAULT NULL COMMENT 'GLUE备注',
  `glue_updatetime` datetime DEFAULT NULL COMMENT 'GLUE更新时间',
  `child_jobid` varchar(255) DEFAULT NULL COMMENT '子任务ID,多个逗号分隔',
  `trigger_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '调度状态:0-停止,1-运行',
  `trigger_last_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '上次调度时间',
  `trigger_next_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '下次调度时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT '执行器主键ID',
  `job_id` int(11) NOT NULL COMMENT '任务,主键ID',
  `executor_address` varchar(255) DEFAULT NULL COMMENT '执行器地址,本次执行的地址',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
  `executor_sharding_param` varchar(20) DEFAULT NULL COMMENT '执行器任务分片参数,格式如 1/2',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
  `trigger_time` datetime DEFAULT NULL COMMENT '调度-时间',
  `trigger_code` int(11) NOT NULL COMMENT '调度-结果',
  `trigger_msg` text COMMENT '调度-日志',
  `handle_time` datetime DEFAULT NULL COMMENT '执行-时间',
  `handle_code` int(11) NOT NULL COMMENT '执行-状态',
  `handle_msg` text COMMENT '执行-日志',
  `alarm_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '告警状态:0-默认、1-无需告警、2-告警成功、3-告警失败',
  PRIMARY KEY (`id`),
  KEY `I_trigger_time` (`trigger_time`),
  KEY `I_handle_code` (`handle_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_log_report` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trigger_day` datetime DEFAULT NULL COMMENT '调度-时间',
  `running_count` int(11) NOT NULL DEFAULT '0' COMMENT '运行中-日志数量',
  `suc_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行成功-日志数量',
  `fail_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行失败-日志数量',
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `i_trigger_day` (`trigger_day`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_logglue` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_id` int(11) NOT NULL COMMENT '任务,主键ID',
  `glue_type` varchar(50) DEFAULT NULL COMMENT 'GLUE类型',
  `glue_source` mediumtext COMMENT 'GLUE源代码',
  `glue_remark` varchar(128) NOT NULL COMMENT 'GLUE备注',
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_registry` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `registry_group` varchar(50) NOT NULL,
  `registry_key` varchar(255) NOT NULL,
  `registry_value` varchar(255) NOT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app_name` varchar(64) NOT NULL COMMENT '执行器AppName',
  `title` varchar(12) NOT NULL COMMENT '执行器名称',
  `address_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '执行器地址类型:0=自动注册、1=手动录入',
  `address_list` text COMMENT '执行器地址列表,多地址逗号分隔',
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL COMMENT '账号',
  `password` varchar(50) NOT NULL COMMENT '密码',
  `role` tinyint(4) NOT NULL COMMENT '角色:0-普通用户、1-管理员',
  `permission` varchar(255) DEFAULT NULL COMMENT '权限:执行器ID列表,多个逗号分割',
  PRIMARY KEY (`id`),
  UNIQUE KEY `i_username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_lock` (
  `lock_name` varchar(50) NOT NULL COMMENT '锁名称',
  PRIMARY KEY (`lock_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `address_type`, `address_list`, `update_time`) VALUES (1, 'xxl-job-executor-sample', '示例执行器', 0, NULL, '2018-11-03 22:21:31' );
INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1, 1, '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');
INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');

commit;

2.2.2.下载镜像

https://hub.docker.com/r/xuxueli/xxl-job-admin/

docker pull xuxueli/xxl-job-admin:2.4.0

2.2.3创建容器并运行

书写配置文件application.properties

### web
server.port=8080
server.servlet.context-path=/xxl-job-admin

### actuator
management.server.servlet.context-path=/actuator
management.health.mail.enabled=false

### resources
spring.mvc.servlet.load-on-startup=0
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/

### freemarker
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.suffix=.ftl
spring.freemarker.charset=UTF-8
spring.freemarker.request-context-attribute=request
spring.freemarker.settings.number_format=0.##########

### mybatis
mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
#mybatis.type-aliases-package=com.xxl.job.admin.core.model

### xxl-job, datasource
spring.datasource.url=jdbc:mysql://rm-bp169j3q9n43kxauzco.mysql.rds.aliyuncs.com:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root123
spring.datasource.password=Root_123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

### datasource-pool
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=HikariCP
spring.datasource.hikari.max-lifetime=900000
spring.datasource.hikari.connection-timeout=10000
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.validation-timeout=1000

### xxl-job, email
spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=xxx@qq.com
spring.mail.from=xxx@qq.com
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

### xxl-job, access token
xxl.job.accessToken=default_token

### xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and "en")
xxl.job.i18n=zh_CN

## xxl-job, triggerpool max size
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100

### xxl-job, log retention days
xxl.job.logretentiondays=30

2.2.4挂载并运行如下命令

docker run -d -p 8085:8080 --privileged=true -v /opt/xxl-job/application.properties:/config/application.properties   -v /opt/xxl-job/logs:/data/applogs --name xxl-job-admin  xuxueli/xxl-job-admin:2.4.0

2.2.5登录控制台

调度中心访问地址:http://localhost:8080/xxl-job-admin

默认登录账号 “admin/123456”, 登录后运行界面如下图所示。

2.2.6. 书写-执行器

2.1 引入依赖
<dependency>
            <groupId>com.xuxueli</groupId>
            <artifactId>xxl-job-core</artifactId>
            <version>2.4.0</version>
        </dependency>

 2.2书写执行任务

package com.by.xxljob;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.Method;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class OrderXxljob {
    /**
     * 1、简单任务示例(Bean模式)
     */
    @XxlJob("demoJobHandler")
    public void demoJobHandler() throws Exception {
            XxlJobHelper.log("demoJobHandler执行了" );
            log.debug("demoJobHandler执行了");
    }

    /**
     * 2、简单任务示例(Bean模式)
     */
    @XxlJob("call-rabbitmq")
    public void demoJobHandler2() throws Exception {

        List<String> list=new ArrayList<>();


        String param = XxlJobHelper.getJobParam();
        HashMap hashMap = JSONUtil.toBean(param, HashMap.class);
        Object host = hashMap.get("host");
        Object port = hashMap.get("port");
        String vhostsUrl = StrUtil.format("http://{}:{}/api/vhosts", host, port);
        String body = HttpRequest.of(vhostsUrl).method(Method.GET).header("Authorization", "Basic Z3Vlc3Q6Z3Vlc3Q=").execute().body();
        JSONArray vhosts = JSONUtil.parseArray(body);
        //遍历虚拟机,拿出队列
        for (Object vhost :vhosts) {
            JSONObject jsonObject =(JSONObject)vhost;
            Object vhostsName = jsonObject.get("name");
            String queueUrl = StrUtil.format("http://{}:{}/api/queues/{}", host, port,vhostsName);
            String body1 = HttpRequest.of(queueUrl).method(Method.GET).header("Authorization", "Basic Z3Vlc3Q6Z3Vlc3Q=").execute().body();
            JSONArray queues = JSONUtil.parseArray(body1);
            //遍历队列,拿出消息和消息长度
            for (Object queue :queues) {
                JSONObject queueObject = (JSONObject) queue;
                Integer messageCount = queueObject.getInt("messages");
                String messages = queueObject.getStr("messages");
                Object name = queueObject.get("name");
                if (messageCount >=5 && !list.contains(name)){
//                    String url="https://oapi.dingtalk.com/robot/send?access_token=afa3850182a65faee2ee6913746793f65fb1f858bb7c921aaf5c7c49a9b33d9e";
//                    JSONObject msg=new JSONObject();
//                    msg.set("msgtype", "markdown");
//                    msg.set("at",new JSONObject().set("isAll",true));
//                    msg.set("markdown",new JSONObject()
//                            .set("title","队列"+name+"需要您的审核"));
//
//                    //msg.set("atMobiles", new JSONArray().set("17550579297").set("18537866710"));
//                    //msg.set("at", new JSONObject().set("atMobiles", new JSONArray().set("18336208150")));
//                    String body2 = JSONUtil.toJsonStr(msg);
//                    String L= HttpRequest.post(url)
//                            .body(body2)
//                            .execute().body();
//                    log.debug("发送钉钉审核成功,报警");
                    sendDingDing(name.toString(),messages);
                    list.add(name.toString());
                }else{
                    log.debug("未见异常");
                }
                }
            }
        }
    private void sendDingDing(String name,String message){
        String url = "https://oapi.dingtalk.com/robot/send?access_token=afa3850182a65faee2ee6913746793f65fb1f858bb7c921aaf5c7c49a9b33d9e";
        JSONObject msg = new JSONObject();
        String json= "{\n" +
                "    \"msgtype\": \"text\",\n" +
                "    \"text\": {\n" +
                "        \"content\": \"注意!!!!!队列"+name+"有"+message+"条消息,请及时审核处理朱海洋40\"\n" +
                "    }\n" +
                "}";
        String result = HttpRequest.post(url)
                .body(json)
                .execute().body();
        log.debug("警告发送成功,队列{}的消息{}条,超过了限制",name,message);
    }

    }



配置文件


#xxljob配置
#xxl-job配置
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses=http://localhost:8080/xxl-job-admin

### xxl-job, access token
xxl.job.accessToken=default_token

### xxl-job executor appname
xxl.job.executor.appname=${spring.application.name}
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
xxl.job.executor.address=
### xxl-job executor server-info
xxl.job.executor.ip=

### xxl-job executor log-path
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
### xxl-job executor log-retention-days
xxl.job.executor.logretentiondays=30

执行在控制台查看结果即可。

  • 19
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java分布式调度框架是一种用于分布式系统中任务调度和资源管理的框架。以下是一些常见的Java分布式调度框架: 1. Apache Mesos:Apache Mesos是一个高效的分布式系统内核,它允许在大规模集群中高效运行各种应用程序。它提供了任务调度、资源分配、容错和服务发现等功能。 2. Apache Spark:Apache Spark是一个快速的通用集群计算系统,提供了内存计算和分布式任务调度等功能。它支持多种编程语言,包括Java,并且可以与Hadoop、Hive和HBase等相关生态系统集成。 3. Spring Cloud Data Flow:Spring Cloud Data Flow是一个用于构建和管理大规模数据处理和集成应用程序的分布式系统。它提供了任务调度、数据流管理、实时分析和批处理等功能,并且可以与Spring Boot和Spring Cloud等相关框架集成。 4. Apache Hadoop YARN:Apache Hadoop YARN是Hadoop框架的资源管理和任务调度系统。它通过将任务调度和资源管理分离,实现了更高的系统效率和灵活性。 5. Netflix Fenzo:Netflix Fenzo是一个用于任务调度和资源管理的开源库。它提供了灵活的调度算法和资源分配策略,可以与Mesos和Kubernetes等容编排系统集成。 6. Quartz:Quartz是一个开源的任务调度框架,用于在Java应用程序中执行定时和延迟任务。它支持复杂的调度需求,并且可以与多个任务执行集成,包括集群和分布式环境。 这些框架提供了不同的功能和适用场景,可以根据具体的需求选择最适合的框架。无论是大规模数据处理、实时分析还是定时任务调度,都可以找到适合的Java分布式调度框架来支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值