Collections.synchronizedList在方法中的运用

    public List<GroupImage> queryGroupInfo(String tableName, List<GroupTemplate> groupLists) {
        String sql = "select t1.id,t1.face_id,t1.group_person_id as person_id,t3.url,t1.global_id from " + GlobalConsts.INTELLIF_TASK + "." + tableName
                + " t1 left join " + GlobalConsts.INTELLIF_FACE + ".t_face_";
        List<GroupImage> lists = null;
        try {
            List<GroupImage> resultList = Collections.synchronizedList(new ArrayList<>());
            List<Future<?>> tasklist = new ArrayList<>();


            for (GroupTemplate groupList : groupLists) {
                tasklist.add(ApplicationResource.THREAD_POOL.submit(() -> {
                    List<GroupImage> list = null;
                    long index = CommonUtil.getCode(groupList.getFace_id());
                    if (groupLists.get(0).getId() == groupList.getId()) {
                        list = groupDao.queryGroupImage(sql + index + " t2 on (t1.face_id = t2.id and t1.group_person_id = t2.group_person_id) left join "
                                + GlobalConsts.INTELLIF_FACE + ".t_image_" + index + " t3 on t2.image_id =t3.id where t1.id =" + groupList.getId());
                    } else {
                        list = groupDao.queryGroupImage(sql + index + " t2 on (t1.face_id = t2.id and t1.group_person_id = t2.group_person_id) left join "
                                + GlobalConsts.INTELLIF_FACE + ".t_image_" + index + " t3 on t2.image_id =t3.id where t1.id =" + groupList.getId());
                    }
                    resultList.addAll(list);
                }));
            }
            tasklist.forEach(FunctionUtil::waitTillThreadFinish);
            lists = resultList;
        } catch (Exception e) {
            LOG.info("获取image_url表错误 " + e);
        }


        return lists;
    }

猜你喜欢

转载自blog.csdn.net/yangaliang/article/details/79744210
今日推荐