MCPcopy Create free account
hub / github.com/MyCATApache/Mycat-Server / BatchSQLJob

Class BatchSQLJob

src/main/java/io/mycat/sqlengine/BatchSQLJob.java:9–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import io.mycat.config.model.SystemConfig;
8
9public class BatchSQLJob {
10
11 private ConcurrentHashMap<Integer, SQLJob> runningJobs = new ConcurrentHashMap<Integer, SQLJob>();
12 private ConcurrentLinkedQueue<SQLJob> waitingJobs = new ConcurrentLinkedQueue<SQLJob>();
13 private volatile boolean noMoreJobInput = false;
14 /*
15 *
16 * parallExecute: 是否可以并行执行
17 * */
18 public void addJob(SQLJob newJob, boolean parallExecute) {
19 SystemConfig system = MycatServer.getInstance().getConfig().getSystem();
20 parallExecute = parallExecute && (system.getParallExecute() == 1);
21 if (parallExecute) {
22 runJob(newJob);
23 } else {
24 waitingJobs.offer(newJob);
25 if (runningJobs.isEmpty()) {
26 SQLJob job = waitingJobs.poll();
27 if (job != null) {
28 runJob(job);
29 }
30 }
31 }
32 }
33 //设置批量任务已经不会在添加任务了。
34 public void setNoMoreJobInput(boolean noMoreJobInput) {
35 this.noMoreJobInput = noMoreJobInput;
36 }
37 //执行任务
38 private void runJob(SQLJob newJob) {
39 // EngineCtx.LOGGER.info("run job " + newJob);
40 runningJobs.put(newJob.getId(), newJob);
41 MycatServer.getInstance().getBusinessExecutor().execute(newJob);
42 }
43 //单个的任务执行完毕。 等待任务列表中有任务, 继续执行下一个任务。
44 //返回: 是否所有的任务执行完毕。
45 public boolean jobFinished(SQLJob sqlJob) {
46 if (EngineCtx.LOGGER.isDebugEnabled()) {
47 EngineCtx.LOGGER.info("job finished " + sqlJob);
48 }
49 runningJobs.remove(sqlJob.getId());
50 SQLJob job = waitingJobs.poll();
51 if (job != null) {
52 runJob(job);
53 return false;
54 } else {
55 if (noMoreJobInput) {
56 return runningJobs.isEmpty() && waitingJobs.isEmpty();
57 } else {
58 return false;
59 }
60 }
61
62 }
63}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected