IT-KIMI_SHI\SINOIT.KIMI
2018-06-01 521993214708c66a5498bd669c94a661c11484b2
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
package frame.schedule;
 
import org.apache.log4j.Logger;
import org.quartz.JobKey;
import org.quartz.TriggerKey;
 
 
public abstract class Job implements IJob {
 
    protected static Logger logger;
    private Object lock = new Object();
    private JobStatus status;
    protected String group;
    protected String id;
    protected String name;
    protected String runtime;
    protected JobKey jobKey;
    protected TriggerKey triggerKey;
    
    static {
        logger = Logger.getLogger(Job.class);
    }
    
    public Job(String group, String id) {
        this.group = group;
        this.id = id;
        
        jobKey = new JobKey(id, group);
        triggerKey = new TriggerKey(id, group);
        status = JobStatus.Idle;
    }
    
    public void execute() throws Exception {
        if (JobStatus.Idle == status || JobStatus.Error == status) {
            synchronized (lock) {
                if (JobStatus.Idle == status || JobStatus.Error == status) {
                    doExecute();                
                }
                else {
                    logger.info(name + "自动退出本次运行,前一次运行状态:" + status);
                }
            }
        }
        else {
            logger.info(name + "自动退出本次运行,前一次运行状态:" + status);
        }        
    }
 
    protected abstract void doExecute() throws Exception;
 
    public String getId() {
        return id;
    }
 
    public String getName() {
        return name;
    }
 
    public String getRunTime() {
        return runtime;
    }
 
    public JobKey getJobKey() {
        return jobKey;
    }
 
    public TriggerKey getTriggerKey() {
        return triggerKey;
    }
 
    public JobStatus getStatus() {
        return status;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    public void setRuntime(String runtime) {
        this.runtime = runtime;
    }
}