forked from kidgrow-microservices-platform

dougang
2020-11-04 b5c197d06d35d56a9fbcb379e49ad07698d7dd90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.xxl.job.core.util;
 
/**
 * sharding model
 * @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();
    }
 
}