A distributed task scheduling framework core library for Java applications
npx @tessl/cli install tessl/maven-com-xuxueli--xxl-job-core@3.1.0XXL-Job Core is a distributed task scheduling framework library for Java applications. It provides comprehensive job execution capabilities with cluster deployment, task failover, and real-time monitoring. The library enables developers to build scalable job scheduling systems with embedded Netty server functionality, JSON serialization, Groovy scripting support, and Spring framework integration.
<dependency><groupId>com.xuxueli</groupId><artifactId>xxl-job-core</artifactId><version>3.1.0</version></dependency>import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.context.XxlJobHelper;
import org.springframework.stereotype.Component;
@Component
public class SampleJobHandler {
@XxlJob("demoJobHandler")
public void demoJobHandler() throws Exception {
String param = XxlJobHelper.getJobParam();
XxlJobHelper.log("XXL-JOB, Hello World: {}", param);
// Job logic here
XxlJobHelper.handleSuccess();
}
}
// Configuration
@Configuration
public class XxlJobConfig {
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses("http://127.0.0.1:8080/xxl-job-admin");
xxlJobSpringExecutor.setAppname("xxl-job-executor-sample");
xxlJobSpringExecutor.setAddress("");
xxlJobSpringExecutor.setIp("");
xxlJobSpringExecutor.setPort(9999);
xxlJobSpringExecutor.setAccessToken("");
xxlJobSpringExecutor.setLogPath("/data/applogs/xxl-job/jobhandler");
xxlJobSpringExecutor.setLogRetentionDays(30);
return xxlJobSpringExecutor;
}
}XXL-Job Core is built around several key components:
@XxlJob annotation for marking methods as job handlers with automatic discoveryXxlJobExecutor with Spring and standalone implementationsXxlJobHelper and XxlJobContext for accessing job parameters and loggingAdminBiz, ExecutorBiz) for distributed coordinationCore job definition using annotations and handlers. Essential for creating executable job units that can be scheduled and triggered by the XXL-Job admin system.
// Primary job annotation
@XxlJob(value = "jobName", init = "initMethod", destroy = "destroyMethod")
public @interface XxlJob {
String value();
String init() default "";
String destroy() default "";
}
// Base job handler interface
public abstract class IJobHandler {
public abstract void execute() throws Exception;
public void init() throws Exception {}
public void destroy() throws Exception {}
}Executor lifecycle management for both Spring and standalone environments. Handles registration with admin servers, job thread management, and server communication.
// Core executor class
public class XxlJobExecutor {
public void setAdminAddresses(String adminAddresses);
public void setAccessToken(String accessToken);
public void setAppname(String appname);
public void setAddress(String address);
public void setPort(int port);
public void setLogPath(String logPath);
public void start() throws Exception;
public void destroy();
}
// Spring integration
public class XxlJobSpringExecutor extends XxlJobExecutor
implements ApplicationContextAware, SmartInitializingSingleton, DisposableBean {
// Automatic @XxlJob method discovery
}
// Standalone usage
public class XxlJobSimpleExecutor extends XxlJobExecutor {
public void setXxlJobBeanList(List<Object> xxlJobBeanList);
}Executor Configuration and Management
Runtime context access and logging utilities for job execution. Provides thread-safe access to job parameters, logging, and result handling.
// Context helper utilities
public class XxlJobHelper {
public static long getJobId();
public static String getJobParam();
public static int getShardIndex();
public static int getShardTotal();
public static boolean log(String pattern, Object... arguments);
public static boolean handleSuccess();
public static boolean handleSuccess(String message);
public static boolean handleFail();
public static boolean handleFail(String message);
public static boolean handleTimeout();
}
// Job execution context
public class XxlJobContext {
public static final int HANDLE_CODE_SUCCESS = 200;
public static final int HANDLE_CODE_FAIL = 500;
public static final int HANDLE_CODE_TIMEOUT = 502;
}Context Management and Logging
Remote procedure call interfaces and data models for admin-executor communication. Handles job triggering, status callbacks, and heartbeat monitoring.
// Admin server communication
public interface AdminBiz {
ReturnT<String> callback(List<HandleCallbackParam> callbackParamList);
ReturnT<String> registry(RegistryParam registryParam);
ReturnT<String> registryRemove(RegistryParam registryParam);
}
// Executor communication
public interface ExecutorBiz {
ReturnT<String> beat();
ReturnT<String> idleBeat(IdleBeatParam idleBeatParam);
ReturnT<String> run(TriggerParam triggerParam);
ReturnT<String> kill(KillParam killParam);
ReturnT<LogResult> log(LogParam logParam);
}
// Standard response wrapper
public class ReturnT<T> implements Serializable {
public static final int SUCCESS_CODE = 200;
public static final int FAIL_CODE = 500;
public static final ReturnT<String> SUCCESS;
public static final ReturnT<String> FAIL;
}Communication Interfaces and Models
Enums, constants, and utility classes for job execution strategies, script types, and system configuration.
// Execution blocking strategies
public enum ExecutorBlockStrategyEnum {
SERIAL_EXECUTION("Serial execution"),
DISCARD_LATER("Discard Later"),
COVER_EARLY("Cover Early");
public String getTitle();
public static ExecutorBlockStrategyEnum match(String name, ExecutorBlockStrategyEnum defaultItem);
}
// Supported script types
public enum GlueTypeEnum {
BEAN, GLUE_GROOVY, GLUE_SHELL, GLUE_PYTHON, GLUE_PHP, GLUE_NODEJS, GLUE_POWERSHELL;
public String getDesc();
public boolean isScript();
public static GlueTypeEnum match(String name);
}Core thread classes and infrastructure components for job execution, registration, callback handling, and embedded server management.
// Core job execution thread
public class JobThread extends Thread {
public ReturnT<String> pushTriggerQueue(TriggerParam triggerParam);
public void toStop(String stopReason);
public boolean isRunningOrHasQueue();
}
// Registry management thread
public class ExecutorRegistryThread {
public static ExecutorRegistryThread getInstance();
public void start(String adminAddresses, String accessToken, String appname, String address);
public void toStop();
}
// Embedded HTTP server
public class EmbedServer {
public void start(String address, int port, String appname, String accessToken) throws Exception;
public void stop() throws Exception;
}