package com.yssh.service; import java.util.List; import java.util.concurrent.CountDownLatch; import org.springframework.stereotype.Service; import com.yssh.mapper.BaseMapper; @Service public class AsyncService { public static final Integer BATCH_INSERT_NUMBER = 1000; public static final Integer BATCH_INSERT_500 = 500; public void executeAsync(String tableName, List lists, BaseMapper mapper, CountDownLatch countDownLatch) { try{ //异步线程要做的事情 mapper.batchInsert(tableName, lists); }finally { countDownLatch.countDown();// 很关键, 无论上面程序是否异常必须执行countDown,否则await无法释放 } } }