diff --git a/renren-admin/src/main/java/io/renren/modules/fuse/service/impl/TbFuseServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/fuse/service/impl/TbFuseServiceImpl.java index 31bb12d2..a1cd5e16 100644 --- a/renren-admin/src/main/java/io/renren/modules/fuse/service/impl/TbFuseServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/fuse/service/impl/TbFuseServiceImpl.java @@ -168,31 +168,45 @@ public class TbFuseServiceImpl extends CrudServiceImpl completableFutures=new CopyOnWriteArrayList<>(); - while(end.get()){ + do { completableFutures.add(CompletableFuture.supplyAsync(()->{ Optional factory = DataResourceFactory.build(); if (factory.isPresent()) { - GetDataResourceListDto dto=new GetDataResourceListDto().setPageNum(pageIndex.get()).setPageSize(pageSize); - Map dataResource = (Map) factory.get().getDataResource(dto); - if(!dataResource.isEmpty()){ - List> list = (List>) dataResource.get("data"); - pageIndex.getAndIncrement(); - return new HashMap(){{put( list.stream().map(map->{ - if (map.containsKey("zyname")) { - return map.get("guid"); - } else { - return map.get("serviceId"); - } - }), list);}}; + try { + GetDataResourceListDto dto=new GetDataResourceListDto().setPageNum(pageIndex.get()).setPageSize(pageSize); + Map dataResource = (Map) factory.get().getDataResource(dto); + if(!dataResource.isEmpty()){ + List> list = (List>) dataResource.get("data"); + pageIndex.getAndIncrement(); + return new HashMap(){{put( list.stream().map(map->{ + if (map.containsKey("zyname")) { + return map.get("guid"); + } else { + return map.get("serviceId"); + } + }), list);}}; + } + } catch (Exception e) { + logger.info("获取数据资源异常:", e); + end.set(false); } } - return null; + return new HashMap<>(); }).thenAcceptAsync(map->{ - if(map != null){ + if(!map.isEmpty()){ result.putAll(map); + }else{ + end.set(false); } })); - } + + try { + Thread.sleep(300); // 防止任务运行过快,无法跳出循环 + } catch (InterruptedException e) { + logger.info("获取数据资源异常", e); + } + + } while(end.get()); return result; } @@ -204,7 +218,7 @@ public class TbFuseServiceImpl extends CrudServiceImpl list = fuseResourceDao.selectList(wrapper); Map> resourceMap = list.stream().filter(index -> index.getType() != null).collect(Collectors.groupingBy(TbFuseResourceEntity::getType)); if (resourceMap.containsKey("数据资源")) { - //dataResourceMap.putAll(getDataResource()); + dataResourceMap.putAll(getDataResource()); } resourceMap.forEach((type, value) -> { if ("组件服务".equals(type)) {