xiangpei
2025-05-22 631e9d709d7e3f420a2ef8017d1d680f4e32ede6
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.xxl.job.core.context;
 
/**
 * xxl-job context
 *
 * @author xuxueli 2020-05-21
 * [Dear hj]
 */
public class XxlJobContext {
 
    public static final int HANDLE_COCE_SUCCESS = 200;
    public static final int HANDLE_COCE_FAIL = 500;
    public static final int HANDLE_COCE_TIMEOUT = 502;
 
    // ---------------------- base info ----------------------
 
    /**
     * job id
     */
    private final long jobId;
 
    /**
     * job param
     */
    private final String jobParam;
 
    // ---------------------- for log ----------------------
 
    /**
     * job log filename
     */
    private final String jobLogFileName;
 
    // ---------------------- for shard ----------------------
 
    /**
     * shard index
     */
    private final int shardIndex;
 
    /**
     * shard total
     */
    private final int shardTotal;
 
    // ---------------------- for handle ----------------------
 
    /**
     * handleCode:The result status of job execution
     *
     *      200 : success
     *      500 : fail
     *      502 : timeout
     *
     */
    private int handleCode;
 
    /**
     * handleMsg:The simple log msg of job execution
     */
    private String handleMsg;
 
 
    public XxlJobContext(long jobId, String jobParam, String jobLogFileName, int shardIndex, int shardTotal) {
        this.jobId = jobId;
        this.jobParam = jobParam;
        this.jobLogFileName = jobLogFileName;
        this.shardIndex = shardIndex;
        this.shardTotal = shardTotal;
 
        this.handleCode = HANDLE_COCE_SUCCESS;  // default success
    }
 
    public long getJobId() {
        return jobId;
    }
 
    public String getJobParam() {
        return jobParam;
    }
 
    public String getJobLogFileName() {
        return jobLogFileName;
    }
 
    public int getShardIndex() {
        return shardIndex;
    }
 
    public int getShardTotal() {
        return shardTotal;
    }
 
    public void setHandleCode(int handleCode) {
        this.handleCode = handleCode;
    }
 
    public int getHandleCode() {
        return handleCode;
    }
 
    public void setHandleMsg(String handleMsg) {
        this.handleMsg = handleMsg;
    }
 
    public String getHandleMsg() {
        return handleMsg;
    }
 
    // ---------------------- tool ----------------------
 
    private static InheritableThreadLocal<XxlJobContext> contextHolder = new InheritableThreadLocal<XxlJobContext>(); // support for child thread of job handler)
 
    public static void setXxlJobContext(XxlJobContext xxlJobContext){
        contextHolder.set(xxlJobContext);
    }
 
    public static XxlJobContext getXxlJobContext(){
        return contextHolder.get();
    }
 
}