地质所 沉降监测网建设项目
zmk
2024-07-03 41750848c6cc6506fa107036d04b28c0f28cfba8
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
package com.javaweb.common.utils.thread.parallel;
 
 
 
import com.javaweb.common.utils.thread.MultiThreadHandler;
import com.javaweb.common.utils.thread.exception.ChildThreadException;
 
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
 
 
/**
 * 并行线程处理
 * @author zengyuanjun
 */
public abstract class AbstractMultiParallelThreadHandler implements MultiThreadHandler {
    /**
     * 子线程倒计数锁
     */
    protected CountDownLatch childLatch;
    
    /**
     * 任务列表
     */
    protected List<Runnable> taskList;
    
    /**
     * 子线程异常
     */
    protected ChildThreadException childThreadException;
 
    public AbstractMultiParallelThreadHandler() {
        taskList = new ArrayList<Runnable>();
        childThreadException = new ChildThreadException();
    }
 
    public void setCountDownLatch(CountDownLatch latch) {
        this.childLatch = latch;
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public void addTask(Runnable... tasks) {
        if (null == tasks) {
            taskList = new ArrayList<Runnable>();
        }
        for (Runnable task : tasks) {
            taskList.add(task);
        }
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public abstract void run() throws ChildThreadException;
 
}