提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.timer.jobhandler; |
懒 |
2 |
|
|
3 |
import com.xxl.job.core.biz.model.ReturnT; |
|
4 |
import com.xxl.job.core.handler.IJobHandler; |
|
5 |
import com.xxl.job.core.handler.annotation.JobHandler; |
|
6 |
import com.xxl.job.core.log.XxlJobLogger; |
|
7 |
import com.xxl.job.core.util.ShardingUtil; |
|
8 |
|
|
9 |
/** |
|
10 |
* 分片广播任务 |
|
11 |
* |
|
12 |
* @author xuxueli 2017-07-25 20:56:50 |
|
13 |
*/ |
|
14 |
@JobHandler(value = "shardingJobHandler") |
|
15 |
public class ShardingJobHandler extends IJobHandler { |
|
16 |
|
|
17 |
@Override |
|
18 |
public ReturnT<String> execute(String param) throws Exception { |
|
19 |
|
|
20 |
// 分片参数 |
|
21 |
ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo(); |
|
22 |
XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardingVO.getIndex(), shardingVO.getTotal()); |
|
23 |
|
|
24 |
// 业务逻辑 |
|
25 |
for (int i = 0; i < shardingVO.getTotal(); i++) { |
|
26 |
if (i == shardingVO.getIndex()) { |
|
27 |
XxlJobLogger.log("第 {} 片, 命中分片开始处理", i); |
|
28 |
} else { |
|
29 |
XxlJobLogger.log("第 {} 片, 忽略", i); |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
return SUCCESS; |
|
34 |
} |
|
35 |
|
|
36 |
} |