线程池调整
This commit is contained in:
parent
cd87eb6072
commit
d84737dbd6
|
@ -82,7 +82,8 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
@Service
|
||||
public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEntity, ResourceDTO> implements ResourceService {
|
||||
private Integer cpuNUm = Runtime.getRuntime().availableProcessors();
|
||||
private static final Integer cpuNUm = Runtime.getRuntime().availableProcessors();
|
||||
private static final ExecutorService executor = Executors.newWorkStealingPool(cpuNUm * 3);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceServiceImpl.class);
|
||||
|
||||
|
@ -570,7 +571,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
} catch (Exception exception) {
|
||||
logger.error("青岛西海岸失败", exception);
|
||||
}
|
||||
});
|
||||
}, executor);
|
||||
CompletableFuture local =
|
||||
CompletableFuture.runAsync(() -> { // 金宏网
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
@ -589,7 +590,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
} catch (Exception exception) {
|
||||
logger.error("青岛西海岸失败", exception);
|
||||
}
|
||||
});
|
||||
}, executor);
|
||||
CompletableFuture all = CompletableFuture.allOf(cloud, local);
|
||||
all.join();
|
||||
return result_.stream().filter(Objects::nonNull).findAny().orElse(0l);
|
||||
|
@ -758,7 +759,6 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
@Override
|
||||
@Cacheable(value = selectDeptListKey, key = "#p1")
|
||||
public Object selectDeptList(JSONObject jsonObject, String type) {
|
||||
final ExecutorService executor = Executors.newFixedThreadPool(cpuNUm * 2);
|
||||
List<Map> resultList = new CopyOnWriteArrayList<>();
|
||||
HashMap<String, Object> resourceMap = new HashMap<>();
|
||||
resourceMap.put("type", "全部能力目录");
|
||||
|
@ -1093,7 +1093,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
end.set(false);
|
||||
return new JSONArray();
|
||||
}
|
||||
}).thenAcceptAsync(list -> {
|
||||
}, executor).thenAcceptAsync(list -> {
|
||||
logger.info("知识库数据量:{}", list.size());
|
||||
if (list.size() < 1) {
|
||||
end.set(false);
|
||||
|
@ -1146,7 +1146,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
this.insertWithAttrs(dto);
|
||||
logger.info("插入:" + dto.getName());
|
||||
});
|
||||
}));
|
||||
}, executor));
|
||||
try {
|
||||
Thread.sleep(300L);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -1222,7 +1222,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer resourceCarNum = baseDao.selectResourceCarNum(hashMap);
|
||||
dept.put("resourceCarNum", resourceCarNum);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> voidCompletableFuture02 = CompletableFuture.runAsync(() -> { // 获取被被收藏数量
|
||||
result.forEach(dept -> {
|
||||
|
@ -1231,7 +1231,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer resourceCollectionNum = baseDao.selectResourceCollectionNum(hashMap);
|
||||
dept.put("resourceCollectionNum", resourceCollectionNum);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> voidCompletableFuture03 = CompletableFuture.runAsync(() -> { // 获取被被浏览数量
|
||||
result.forEach(dept -> {
|
||||
|
@ -1240,7 +1240,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer resourceBrowseNum = baseDao.selectResourceBrowseNum(hashMap);
|
||||
dept.put("resourceBrowseNum", resourceBrowseNum);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> voidCompletableFuture04 = CompletableFuture.runAsync(() -> { // 获取被被应用数量
|
||||
result.forEach(dept -> {
|
||||
|
@ -1249,7 +1249,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer resourceRelNum = baseDao.selectResourceRelNum(hashMap);
|
||||
dept.put("resourceRelNum", resourceRelNum);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> voidCompletableFuture05 = CompletableFuture.runAsync(() -> { // 获取需申请数量 免批数量
|
||||
result.forEach(dept -> {
|
||||
|
@ -1262,7 +1262,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer resourceShareNonNum = baseDao.selectResourceShare(hashMap);
|
||||
dept.put("resourceShareNonNum", resourceShareNonNum);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
//还缺少被调用总数
|
||||
CompletableFuture<Void> all = CompletableFuture.allOf(voidCompletableFuture01, voidCompletableFuture02, voidCompletableFuture03, voidCompletableFuture04, voidCompletableFuture05);
|
||||
|
@ -1308,7 +1308,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer integer = baseDao.selectResourceBrowseNum(params);
|
||||
r.put("resourceBrowseNum", integer);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> voidCompletableFuture02 = CompletableFuture.runAsync(() -> { //应用收藏量
|
||||
result.forEach(r -> {
|
||||
|
@ -1316,7 +1316,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer integer = baseDao.selectResourceCollectionNum(params);
|
||||
r.put("resourceCollectionNum", integer);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> all = CompletableFuture.allOf(voidCompletableFuture01, voidCompletableFuture02);
|
||||
all.join();
|
||||
|
@ -1361,21 +1361,21 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer integer = baseDao.selectResourceCarNum(params);
|
||||
r.put("resourceCarNum", integer);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> resourceCollectionNum02 = CompletableFuture.runAsync(() -> {//被浏览数量
|
||||
result.forEach(r -> {
|
||||
Integer integer = baseDao.selectResourceBrowseNum(params);
|
||||
r.put("resourceBrowseNum", integer);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> resourceCollectionNum03 = CompletableFuture.runAsync(() -> {//被收藏数量
|
||||
result.forEach(r -> {
|
||||
Integer integer = baseDao.selectResourceCollectionNum(params);
|
||||
r.put("resourceCollectionNum", integer);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> all = CompletableFuture.allOf(resourceCollectionNum01, resourceCollectionNum02, resourceCollectionNum03);
|
||||
all.join();
|
||||
|
@ -1420,21 +1420,21 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
Integer integer = baseDao.selectResourceCarNum(params);
|
||||
re.put("resourceCarNum", integer);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> resourceBrowseNum = CompletableFuture.runAsync(() -> { //被浏览数量
|
||||
result.forEach(re -> {
|
||||
Integer integer = baseDao.selectResourceBrowseNum(params);
|
||||
re.put("resourceBrowseNum", integer);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> resourceCollectionNum = CompletableFuture.runAsync(() -> { //被收藏数量
|
||||
result.forEach(re -> {
|
||||
Integer integer = baseDao.selectResourceCollectionNum(params);
|
||||
re.put("resourceCollectionNum", integer);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> all = CompletableFuture.allOf(resourceCarNum, resourceBrowseNum, resourceCollectionNum);
|
||||
all.join();
|
||||
|
@ -1526,13 +1526,13 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
|
|||
m.put("resourceUseNum", maps2.get("useNum") == null ? 0 : maps2.get("useNum"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
//还缺少组件调用数,这先用假数据代替
|
||||
CompletableFuture<Void> voidCompletableFuture01 = CompletableFuture.runAsync(() -> {
|
||||
maps.forEach(m -> {
|
||||
m.put("resourceCallNum", 0);
|
||||
});
|
||||
});
|
||||
}, executor);
|
||||
|
||||
CompletableFuture<Void> all = CompletableFuture.allOf(voidCompletableFuture01, voidCompletableFuture02);
|
||||
all.join();
|
||||
|
|
Loading…
Reference in New Issue