燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-04-27 bf27e24f68cf41a07ba0e5c4dc6ac1c086b6652d
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
package com.yssh.service.impl;
 
import java.util.List;
import java.util.concurrent.CountDownLatch;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
 
import com.yssh.dao.BaseMapper;
import com.yssh.service.IAsyncService;
 
 
@Service
public class AsyncServiceImpl implements IAsyncService {
 
    protected final Log logger = LogFactory.getLog(this.getClass());
    
 
    @Override
    public <T> void executeAsync(String tableName, List<T> lists, BaseMapper mapper, CountDownLatch countDownLatch) {
        try{
            //异步线程要做的事情
            mapper.batchInsert(tableName, lists);
        }finally {
            countDownLatch.countDown();// 很关键, 无论上面程序是否异常必须执行countDown,否则await无法释放
        }
    }
 
}