/java-skills:xxl-job-patternsfrom java-skills
XXL-JOB best practices using @XxlJobCron annotation (code-as-config, auto-register to Admin), XxlJobTemplate for programmatic job CRUD/trigger/session renewal, executor auto-config (Unirest SSL, port fallback, Nacos), Micrometer metrics, and v2/v3 compatibility.
Ships in java-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
来源:https://github.com/xuxueli/xxl-job
基于 hiwepy/xxljob-spring-boot-starter(Spring Boot Starter 封装)
@Slf4j
@Component
@RequiredArgsConstructor
public class CompensationJobHandler {
private final AigcTaskCompensationScheduler compensationScheduler;
// ✅ 一行注解 = @XxlJob + cron + desc + author + selfStarting(自动注册到Admin)
@XxlJobCron(value = "compensateStaleTextTasks",
cron = "0/30 * * * * ?",
desc = "文本回调超时补偿",
author = "wandl",
selfStarting = true, // ← 启动时自动注册,无需在Admin UI手动创建
failRetryCount = 3,
timeout = 30) // 30秒超时
public void compensateStaleTextTasks() {
try {
compensationScheduler.compensateStaleTextTasks();
XxlJobHelper.handleSuccess("compensation completed");
} catch (Exception e) {
log.error("XXL-Job failed", e);
XxlJobHelper.handleFail("failed: " + e.getMessage());
}
}
}
@Service
public class JobManager {
@Autowired XxlJobTemplate xxlJobTemplate;
// 创建/更新任务(幂等)
public void ensureJobRegistered(Long jobGroupId, String handlerName, String cron, String desc) {
XxlJobInfo jobInfo = new XxlJobInfo();
jobInfo.setJobGroup(jobGroupId.intValue());
jobInfo.setExecutorHandler(handlerName);
jobInfo.setScheduleConf(cron);
jobInfo.setJobDesc(desc);
jobInfo.setScheduleType("CRON");
jobInfo.setGlueType("BEAN");
jobInfo.setAuthor("system");
jobInfo.setExecutorRouteStrategy("LEAST_FREQUENTLY_USED");
jobInfo.setMisfireStrategy("DO_NOTHING");
jobInfo.setExecutorBlockStrategy("COVER_EARLY");
jobInfo.setExecutorTimeout(30);
jobInfo.setExecutorFailRetryCount(3);
xxlJobTemplate.addUniqueJob(jobInfo); // 幂等:描述相同不重复创建
}
// 手动触发
public void triggerJob(Integer jobId, String param) {
xxlJobTemplate.triggerJob(jobId, param);
}
// 暂停/恢复
public void pauseJob(Integer jobId) { xxlJobTemplate.stopJob(jobId); }
public void resumeJob(Integer jobId) { xxlJobTemplate.startJob(jobId); }
}
xxl:
job:
accessToken: xxx # 通信Token
admin:
version: V3_X # Admin版本(V2_X / V3_X)
addresses: http://xxx:9991/xxl-job-admin
username: admin
password: xxxxx # Admin登录密码
cookie: # Session管理
maximum-size: 1000
expire-after-write: 5s
executor:
enabled: true
appname: agent-job-executor # 执行器名称(与Admin注册一致)
title: 智能体 - 任务执行器 # 执行器显示名称
ip: 172.16.0.152 # 执行器IP(多网卡时指定)
port: 0 # 0=自动探测,-1=不启动
log-path: /logs/xxl-job/jobhandler
log-retention-days: 30
// ✅ DDD4J 风格:Lombok + 构造器注入
@Slf4j
@Component
@RequiredArgsConstructor // final字段自动构造器注入
public class MyJobHandler {
private final OrderService orderService; // 构造器注入
private final NotificationService notifyService;
@XxlJobCron(value = "closeExpiredOrders", cron = "0 0 2 * * ?",
desc = "关闭过期订单", author = "system", selfStarting = true)
public void execute() { ... }
}
@XxlJobCron(...)
public void execute() {
try {
// 业务逻辑
doWork();
XxlJobHelper.handleSuccess("处理完成"); // ← 显式标记成功
} catch (Exception e) {
log.error("XXL-Job {} failed", getJobName(), e);
XxlJobHelper.handleFail("失败: " + e.getMessage()); // ← 显式标记失败
}
}
id,v3用ids[],Starter自动适配xxl.job.executor.ipMetricMethodJobHandler 通过反射读取 @XxlJob.value(),但 @XxlJobCron 不包含原生 @XxlJob 注解,导致 NullPointerException: Cannot invoke "com.xxl.job.core.handler.annotation.XxlJob.value()" because "job" is null。解决方案:① 禁用 Micrometer 指标(xxl.job.metrics.enabled=false) ② 同时在方法上添加空的 @XxlJob 注解解决反射问题 ③ 升级 hiwepy starter 版本看是否已修复本技能不收集、存储或传输任何用户数据。
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
39 skills in this plugin
/caffeine-patternsCaffeine JVM 本地缓存技能。覆盖本地缓存 vs 远程缓存(Redis)选择决策树、expireAfterWrite vs expireAfterAccess vs refreshAfterWrite 三种过期策略对比与组合规则(refresh < expire)、CacheLoader加载与reload异步刷新模式、Spring Cache @Cacheable集成、maximumSize驱逐策略、recordStats缓存统计。 纠正 LLM:用 ConcurrentHashMap+手动过期、所有缓存走Redis、refreshAfterWrite > expireAfterWrite导致永远不刷新、CacheLoader返回null导致缓存穿透。/commons-patternsApache Commons 最佳实践模式。从官方文档提炼,覆盖 Commons Lang3(StringUtils千面判空/isEmpty vs isBlank/Validate抛NullPointerException迁移)、Commons IO(IOUtils.toString大文件陷阱/FileUtils.lineIterator逐行读模式/FilenameUtils.normalize路径规范化)、Commons Collections4(CollectionUtils.union/intersection/subtract集合运算)。 纠正 LLM 误用:混淆 StringUtils.isBlank vs isEmpty、IOUtils.toString 读大文件OOM、不知道 LineIterator 逐行读模式、用 lang 而非 lang3 包名。/Generated from the plugin's indexed repository (full-stack-skills/java-skills) — no native marketplace selected
npx claudepluginhub p/full-statck-skills-java-skills