- 废弃 "ShardingUtil" 组件:改用 "XxlJobContext.getXxlJobContext().getShardIndex()/getShardTotal();" 获取分片参数;master
parent
668411f8b3
commit
e17797888c
12 changed files with 172 additions and 85 deletions
@ -0,0 +1,68 @@ |
||||
package com.xxl.job.core.context; |
||||
|
||||
/** |
||||
* xxl-job context |
||||
* |
||||
* @author xuxueli 2020-05-21 |
||||
* [Dear hj] |
||||
*/ |
||||
public class XxlJobContext { |
||||
|
||||
/** |
||||
* job id |
||||
*/ |
||||
private final long jobId; |
||||
|
||||
/** |
||||
* job log filename |
||||
*/ |
||||
private final String jobLogFileName; |
||||
|
||||
/** |
||||
* shard index |
||||
*/ |
||||
private final int shardIndex; |
||||
|
||||
/** |
||||
* shard total |
||||
*/ |
||||
private final int shardTotal; |
||||
|
||||
|
||||
public XxlJobContext(long jobId, String jobLogFileName, int shardIndex, int shardTotal) { |
||||
this.jobId = jobId; |
||||
this.jobLogFileName = jobLogFileName; |
||||
this.shardIndex = shardIndex; |
||||
this.shardTotal = shardTotal; |
||||
} |
||||
|
||||
public long getJobId() { |
||||
return jobId; |
||||
} |
||||
|
||||
public String getJobLogFileName() { |
||||
return jobLogFileName; |
||||
} |
||||
|
||||
public int getShardIndex() { |
||||
return shardIndex; |
||||
} |
||||
|
||||
public int getShardTotal() { |
||||
return shardTotal; |
||||
} |
||||
|
||||
|
||||
// ---------------------- tool ----------------------
|
||||
|
||||
private static InheritableThreadLocal<XxlJobContext> contextHolder = new InheritableThreadLocal<XxlJobContext>(); |
||||
|
||||
public static void setXxlJobContext(XxlJobContext xxlJobContext){ |
||||
contextHolder.set(xxlJobContext); |
||||
} |
||||
|
||||
public static XxlJobContext getXxlJobContext(){ |
||||
return contextHolder.get(); |
||||
} |
||||
|
||||
} |
@ -1,46 +1,46 @@ |
||||
package com.xxl.job.core.util; |
||||
|
||||
/** |
||||
* sharding vo |
||||
* @author xuxueli 2017-07-25 21:26:38 |
||||
*/ |
||||
public class ShardingUtil { |
||||
|
||||
private static InheritableThreadLocal<ShardingVO> contextHolder = new InheritableThreadLocal<ShardingVO>(); |
||||
|
||||
public static class ShardingVO { |
||||
|
||||
private int index; // sharding index
|
||||
private int total; // sharding total
|
||||
|
||||
public ShardingVO(int index, int total) { |
||||
this.index = index; |
||||
this.total = total; |
||||
} |
||||
|
||||
public int getIndex() { |
||||
return index; |
||||
} |
||||
|
||||
public void setIndex(int index) { |
||||
this.index = index; |
||||
} |
||||
|
||||
public int getTotal() { |
||||
return total; |
||||
} |
||||
|
||||
public void setTotal(int total) { |
||||
this.total = total; |
||||
} |
||||
} |
||||
|
||||
public static void setShardingVo(ShardingVO shardingVo){ |
||||
contextHolder.set(shardingVo); |
||||
} |
||||
|
||||
public static ShardingVO getShardingVo(){ |
||||
return contextHolder.get(); |
||||
} |
||||
|
||||
} |
||||
//package com.xxl.job.core.util;
|
||||
//
|
||||
///**
|
||||
// * sharding vo
|
||||
// * @author xuxueli 2017-07-25 21:26:38
|
||||
// */
|
||||
//public class ShardingUtil {
|
||||
//
|
||||
// private static InheritableThreadLocal<ShardingVO> contextHolder = new InheritableThreadLocal<ShardingVO>();
|
||||
//
|
||||
// public static class ShardingVO {
|
||||
//
|
||||
// private int index; // sharding index
|
||||
// private int total; // sharding total
|
||||
//
|
||||
// public ShardingVO(int index, int total) {
|
||||
// this.index = index;
|
||||
// this.total = total;
|
||||
// }
|
||||
//
|
||||
// public int getIndex() {
|
||||
// return index;
|
||||
// }
|
||||
//
|
||||
// public void setIndex(int index) {
|
||||
// this.index = index;
|
||||
// }
|
||||
//
|
||||
// public int getTotal() {
|
||||
// return total;
|
||||
// }
|
||||
//
|
||||
// public void setTotal(int total) {
|
||||
// this.total = total;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void setShardingVo(ShardingVO shardingVo){
|
||||
// contextHolder.set(shardingVo);
|
||||
// }
|
||||
//
|
||||
// public static ShardingVO getShardingVo(){
|
||||
// return contextHolder.get();
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
Loading…
Reference in new issue