2021-01-30

       List<AlarmEvent> list = (List<AlarmEvent>) pageResult.getContent();
        List<AlarmEvent> result = new ArrayList<>();
        int threadSize =15;
        int dataSize = list.size();
        int threadNum = dataSize / threadSize + 1;
        // 定义标记,过滤threadNum为整数
        boolean special = dataSize % threadSize == 0;
        List<AlarmEvent> cutList = null;
        //定义固定长度的线程池  防止线程过多
        ExecutorService executorService = Executors.newFixedThreadPool(25);
        List<Callable<List<AlarmEvent>>> tasks = new ArrayList<>();
        for (int i = 0; i < threadNum; i++) {
            if (i == threadNum - 1) {
                if (special) {
                    break;
                }
                cutList = list.subList(threadSize * i, dataSize);
            } else {
                cutList = list.subList(threadSize * i, threadSize * (i + 1));
            }
            final List<AlarmEvent> listStr = cutList;
            Callable<List<AlarmEvent>> data = new LocationHandleThread(listStr);
            tasks.add(data);
        }
        List<Future<List<AlarmEvent>>> futures=executorService.invokeAll(tasks);
        //处理线程返回结果
        if(futures!=null&&futures.size()>0){
            for (Future<List<AlarmEvent>> future:futures){
                result.addAll(future.get());
            }
        }
        executorService.shutdown();  //关闭线程池
        util.exportExcel(result, "报警统计信息");
        long end1 = System.currentTimeMillis();
        log.info(">>>>>>>>>>>>>>>>>>>>>报警导出>>>>>>>>>>>>>>>>>>>>>耗时 " + (end1 - start1) + " ms");
public class LocationHandleThread implements Callable<List<AlarmEvent>> {

    private List<AlarmEvent> data;
    public LocationHandleThread(List<AlarmEvent> data) {
        this.data = data;
    }

    @Override
    public  List<AlarmEvent> call() throws Exception {
            List<AlarmEvent> result = new ArrayList<>();
        synchronized(this) {
            for (AlarmEvent temp : data) {
                double[] gpsCorrectList = GpsCorrect.getGpsCorrectList(temp.getLng() / 1000000, temp.getLat() / 1000000);
                String address = MapLocationAddrUtil.getLocationAddr(gpsCorrectList[0] + "," + gpsCorrectList[1]);
                temp.setAddress(address);
                log.info("=======报警解析地址=====" + address);
                String stateStr = "";
                switch (temp.getState()) {
                    case 1:
                        stateStr = "已确认";
                        break;
                    case 2:
                        stateStr = "误报";
                        break;
                    case 3:
                        stateStr = "未确认";
                        break;
                    default:
                }
                temp.setStateStr(stateStr);
                //log.info("=======报警解析状态====="+stateStr);
                result.add(temp);
            }
        }
        return result;
    }
    public List<AlarmEvent> getData() {
        return data;
    }
    public void setData(List<AlarmEvent> data) {
        this.data = data;
    }


}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一个人是干净或肮脏并不重要,因为肮脏就不会有干净存在,不曾干净过就不知道什么是肮脏,我们不能重演历史,错误造成了分...
    多啦只是梦_阅读 188评论 0 1
  • 你是什么样的人,就会觉得别人是什么样子。和煦宽厚的人迎面总是琥珀色的温柔。努力上进的人觉得身边总有学不完的东西。而...
    一如初衷一路南浔阅读 255评论 0 0
  • 修什么车不重要,重要的是,有一个清晰的思路
    当时少春衫薄阅读 73评论 0 0
  • 看多了影视剧,曾以为生活很戏剧化,其实是戏剧很生活化。
    松光姑娘阅读 126评论 0 0
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 7,584评论 16 22