Junjie
15 小时以前 45052042f06689096093fc86cae36560b2eeb1f0
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
package com.zy.core.task;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
@Component
public class MainProcessTaskSubmitter {
 
    private static final long DEFAULT_SLOW_LOG_THRESHOLD_MS = 1000L;
 
    @Autowired
    private MainProcessAsyncTaskScheduler mainProcessAsyncTaskScheduler;
 
    public boolean submitSerialTask(String laneName,
                                    String taskName,
                                    long minIntervalMs,
                                    Runnable task) {
        return mainProcessAsyncTaskScheduler.submit(
                laneName,
                taskName,
                minIntervalMs,
                DEFAULT_SLOW_LOG_THRESHOLD_MS,
                task
        );
    }
 
    public boolean submitSerialTask(MainProcessLane lane,
                                    String taskName,
                                    long minIntervalMs,
                                    Runnable task) {
        if (lane == null) {
            return false;
        }
        return submitSerialTask(lane.laneName(), taskName, minIntervalMs, task);
    }
 
    public boolean submitKeyedSerialTask(String lanePrefix,
                                         Object laneKey,
                                         String taskName,
                                         long minIntervalMs,
                                         Runnable task) {
        if (laneKey == null) {
            return false;
        }
        return submitSerialTask(lanePrefix + laneKey, taskName, minIntervalMs, task);
    }
 
    public boolean submitKeyedSerialTask(MainProcessLane lane,
                                         Object laneKey,
                                         String taskName,
                                         long minIntervalMs,
                                         Runnable task) {
        if (lane == null) {
            return false;
        }
        String laneName = lane.keyedLaneName(laneKey);
        if (laneName == null) {
            return false;
        }
        return submitSerialTask(laneName, taskName, minIntervalMs, task);
    }
}