SpringBoot 集成xxl-job

一、概述:

XXL-JOB是一个分布式任务调度平台,其核心设计目标是开发迅速、学习简单、轻量级、易扩展。现已开放源代码并接入多家公司线上产品线,开箱即用。

官网地址:https://www.xuxueli.com/xxl-job/

二、集成SpringBoot

  1. 引入MAVEN

    复制代码
     		<dependency>
                 <groupId>com.xuxueli</groupId>
                 <artifactId>xxl-job-core</artifactId>
                 <version>${xxl-job-core.version}</version>
             </dependency>
  2. applicaiton.yaml 配置

    xxl:
    job:
    admin:
    addresses: http://192.168.0.22:9080/lq-xxljob-client/
    accessToken:
    executor:
    port: 0
    appname: ${spring.application.name}
    corePoolSize: 5
    maxPoolSize: 20
    threadkeepAliveSeconds: 60
    logPath: logs/lq/job/jobhandler/
    logRetentionDays: 30

  3. XxlJobConfig 配置

    package com.lq.common.config;

    import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;

    @Configuration
    @Slf4j
    public class XxlJobConfig {
    @Value("{xxl.job.admin.addresses}") private String adminAddresses; @Value("{xxl.job.executor.appname}")
    private String appName;
    @Value("{xxl.job.accessToken}") private String accessToken; @Value("{xxl.job.executor.logPath}")
    private String logPath;
    @Value("{xxl.job.executor.logRetentionDays:30}") private int logRetentionDays; // @Value("{xxl.job.executor.ip}")
    // private String ip;
    @Value("${xxl.job.executor.port}")
    private int port;

    复制代码
     @Bean(initMethod = "start", destroyMethod = "destroy")
     public XxlJobSpringExecutor xxlJobExecutor() {
         log.info(">>>>>>>>>>> xxl-job config init.");
         XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
         xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
         xxlJobSpringExecutor.setAppname(appName);
         //        xxlJobSpringExecutor.setIp(ip);
         xxlJobSpringExecutor.setPort(port);
         xxlJobSpringExecutor.setAccessToken(accessToken);
         xxlJobSpringExecutor.setLogPath(logPath);
         xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
    
         return xxlJobSpringExecutor;
     }

    }

常见问题:

在使用XXL-JOB时,出现ERROR com.xxl.job.core.util.XxlJobRemotingUtil:143 - Read timed out错误通常表示在客户端与服务器端进行通信时,读操作超时。XXL-JOB是一个分布式任务调度平台,该错误可能由以下几个原因导致:

网络问题:XXL-JOB客户端与服务端之间的网络连接不稳定或延迟过高,导致在指定的超时时间内无法完成数据读取。

解决方案:检查并确保客户端与服务端之间的网络连通性良好,减少网络延迟和丢包率,必要时可适当增加通信超时时间。

服务端响应过慢:XXL-JOB服务端处理请求的速度太慢,未能在设置的Socket读取超时时间内返回结果。

解决方案:优化服务端性能,排查是否存在阻塞、资源耗尽等情况,确保服务端能够快速响应客户端请求。

配置不合理:XXL-JOB客户端或服务端的相关配置(如超时时间)设置得过小,不足以应对正常业务场景下的响应时间。

解决方案:调整相关超时配置参数,使其适应实际的业务需求和网络环境。

请根据实际情况,针对性地进行排查和解决。同时,关注XXL-JOB服务端日志以获取更详细的错误信息,这对于定位问题源头非常有帮助

解决方法:

yaml 里添加配置

复制代码
 corePoolSize: 5
 maxPoolSize: 20
 threadkeepAliveSeconds: 60
相关推荐
CoderYanger12 小时前
C.滑动窗口-求子数组个数-越长越合法——2799. 统计完全子数组的数目
java·c语言·开发语言·数据结构·算法·leetcode·职场和发展
C++业余爱好者12 小时前
Java 提供了8种基本数据类型及封装类型介绍
java·开发语言·python
想用offer打牌12 小时前
RocketMQ如何防止消息丢失?
java·后端·架构·开源·rocketmq
皮卡龙12 小时前
Java常用的JSON
java·开发语言·spring boot·json
利刃大大13 小时前
【JavaSE】十三、枚举类Enum && Lambda表达式 && 列表排序常见写法
java·开发语言·枚举·lambda·排序
float_六七13 小时前
Java反射:万能遥控器拆解编程
java·开发语言
han_hanker13 小时前
java 异常类——详解
java·开发语言
源码获取_wx:Fegn089513 小时前
基于springboot + vue健身房管理系统
java·开发语言·前端·vue.js·spring boot·后端·spring
峥嵘life13 小时前
Android16 EDLA 认证测试CTS问题分析解决
android·java·服务器
Mr1ght13 小时前
为什么 InheritableThreadLocal 在 Spring 线程池中“偶尔”能传递变量?——一次线程池上下文传播的误解
java·spring