ForkJoinPool线程池用完释放

This commit is contained in:
jeelowcode
2025-03-28 10:25:22 +08:00
parent 723132bc58
commit 33f4588e7f
7 changed files with 140 additions and 63 deletions

View File

@@ -28,10 +28,12 @@ import com.jeelowcode.core.framework.mapper.FormFieldWebMapper;
import com.jeelowcode.core.framework.params.model.WebFormatConfigModel;
import com.jeelowcode.core.framework.service.IFormService;
import com.jeelowcode.core.framework.utils.Func;
import com.jeelowcode.framework.utils.utils.FuncBase;
import org.apache.commons.collections4.map.LinkedMap;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
/**
@@ -81,8 +83,10 @@ public class ButtonReceiverBase {
Set<String> webViewFieldSet = new HashSet<>(formService.getWebViewFieldList(dbFormId));
Map<String, DbFormRoleFieldVo> finalRoleDisableMap = roleDisableMap;
ForkJoinPool pool = null;
try {
Func.jeelowcodeForkJoinPool().submit(() -> records.parallelStream().forEach(recordMap -> recordMap.keySet().removeIf(key -> {
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> records.parallelStream().forEach(recordMap -> recordMap.keySet().removeIf(key -> {
if(Func.equals(key,"jeelowcode_subtable_data") || Func.equals(key,"hasChildren") || Func.equals(key,"leaf")){
return false;
}
@@ -98,6 +102,10 @@ public class ButtonReceiverBase {
}))).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
}
}

View File

@@ -32,11 +32,13 @@ import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
import com.jeelowcode.framework.utils.model.ResultDataModel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeelowcode.framework.utils.utils.FuncBase;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
@Tag(name = "低代码框架-公共框架接口")
public class BaseController {
@@ -326,8 +328,10 @@ public class BaseController {
protected void formatFormEntityPageVo(List<FormEntityPageVo> records, IFormService dbFormService){
ForkJoinPool pool = null;
try {
Func.jeelowcodeForkJoinPool().submit(() -> records.parallelStream().forEach(vo ->{
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> records.parallelStream().forEach(vo ->{
Map<String, Object> couMap = dbFormService.getFormCou(vo.getId());
Integer js_cou = Func.getMap2IntDefault(couMap, "js_cou",0);
Integer scss_cou = Func.getMap2IntDefault(couMap, "scss_cou",0);
@@ -345,6 +349,10 @@ public class BaseController {
})).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
}
}

View File

@@ -66,6 +66,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
@Tag(name = "低代码框架-框架接口")
@@ -232,8 +233,10 @@ public class DbFormController extends BaseController {
}
Map<String, List<Map<String, Object>>> resultMap = new ConcurrentHashMap<>();
ForkJoinPool pool = null;
try {
Func.jeelowcodeForkJoinPool().submit(() -> labelParamList.parallelStream().forEach(labelParam ->{
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> labelParamList.parallelStream().forEach(labelParam ->{
Long dbformId = labelParam.getDbformId();
List<String> fieldList = labelParam.getFieldList();
String code = labelParam.getCode();
@@ -279,6 +282,10 @@ public class DbFormController extends BaseController {
})).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
}
return BaseWebResult.success(resultMap);

View File

@@ -20,6 +20,7 @@ import com.jeelowcode.core.framework.utils.Func;
import com.jeelowcode.core.framework.utils.FuncWeb;
import com.jeelowcode.framework.exception.JeeLowCodeException;
import com.jeelowcode.framework.utils.model.ResultDataModel;
import com.jeelowcode.framework.utils.utils.FuncBase;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
@@ -59,8 +60,10 @@ public class ReportDataController extends BaseController {
Map<String, Object> params = FuncWeb.getParameterBodyMap(req);
List<String> reportCodeList = Func.toStrList(reportCodeListStr);
Map<String, ResultDataModel> resultMap = new ConcurrentHashMap<>();
ForkJoinPool pool = null;
try {
Func.jeelowcodeForkJoinPool().submit(() -> reportCodeList.parallelStream().forEach(reportCode -> {
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> reportCodeList.parallelStream().forEach(reportCode -> {
// 处理代码
Map<String, Object> subParam = (Map) params.get(reportCode);
if (Func.isEmpty(subParam)) {
@@ -71,6 +74,10 @@ public class ReportDataController extends BaseController {
})).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
}
return BaseWebResult.success(resultMap);
}

View File

@@ -62,6 +62,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@@ -363,8 +364,10 @@ public class FrameServiceImpl implements IFrameService {
if (Func.isNotEmpty(summaryTopList)) {
Map<Long, SummaryTopModel> topMap = new ConcurrentHashMap();
//并行流处理
ForkJoinPool pool = null;
try {
Func.jeelowcodeForkJoinPool().submit(() -> summaryTopList.parallelStream().forEach(summaryEntity -> {
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> summaryTopList.parallelStream().forEach(summaryEntity -> {
Long id = summaryEntity.getId();
String summarySql = summaryEntity.getSummarySql();
String summaryLabel = summaryEntity.getSummaryLabel();
@@ -396,6 +399,10 @@ public class FrameServiceImpl implements IFrameService {
})).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
}
//按顺序取出来
summaryTopList.stream().forEach(summaryEntity -> {
@@ -566,8 +573,10 @@ public class FrameServiceImpl implements IFrameService {
AtomicReference<Integer> importState = new AtomicReference<>(1);//成功
String redisKey = "excel:import:task_" + fieldId;//判断是否
AtomicReference<Boolean> breakFlag = new AtomicReference<>(false);
ForkJoinPool pool = null;
try {
Func.jeelowcodeForkJoinPool().submit(() -> entityList.parallelStream().forEach(entity -> {
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> entityList.parallelStream().forEach(entity -> {
if (breakFlag.get()) {//说明退出
return;
}
@@ -615,6 +624,10 @@ public class FrameServiceImpl implements IFrameService {
})).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
}
//如果是取消的话,需要回滚事务
@@ -1370,8 +1383,10 @@ public class FrameServiceImpl implements IFrameService {
if (Func.isEmpty(treeDataList)) {
return;
}
ForkJoinPool pool = null;
try {
Func.jeelowcodeForkJoinPool().submit(() -> treeDataList.parallelStream().forEach(dataMap -> {
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> treeDataList.parallelStream().forEach(dataMap -> {
Long id = Func.getMap2Long(dataMap, "id");
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
@@ -1388,6 +1403,10 @@ public class FrameServiceImpl implements IFrameService {
})).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
}
}

View File

@@ -459,12 +459,18 @@ public class Func extends FuncBase {
public static void handlePlusDataList(List<Map<String, Object>> records, Map<String, JeeLowCodeFieldTypeEnum> fieldTypeEnumMap) {
ForkJoinPool pool = null;
try {
Func.jeelowcodeForkJoinPool().submit(() -> records.parallelStream().forEach(recordMap -> {
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> records.parallelStream().forEach(recordMap -> {
handlePlusDataMap(recordMap, fieldTypeEnumMap);
})).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
}
}

View File

@@ -31,6 +31,8 @@ import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
/**
* 默认值切面
@@ -180,7 +182,7 @@ public class DefaultValAspect {
}
// plus批量新增
private void saveBatchPlus(Object[] args) throws Throwable {
private void saveBatchPlus(Object[] args) {
List list = (List) args[0];
Object o = list.get(0);
if (!(o instanceof BaseEntity || o instanceof BaseTenantEntity)) {//不属于我们的类型
@@ -192,33 +194,43 @@ public class DefaultValAspect {
Long tenantId = proxyAdapter.getTenantId();
Long deptId = proxyAdapter.getOnlineUserDeptId();
FuncBase.jeelowcodeForkJoinPool().submit(() -> list.parallelStream().forEach(obj -> {
//基本类
if (obj instanceof BaseEntity) {//我们自定义的实体
BaseEntity baseEntity = (BaseEntity) obj;
Long createUser = baseEntity.getCreateUser();
Long createDept = baseEntity.getCreateDept();
ForkJoinPool pool = null;
try {
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> list.parallelStream().forEach(obj -> {
//基本类
if (obj instanceof BaseEntity) {//我们自定义的实体
BaseEntity baseEntity = (BaseEntity) obj;
Long createUser = baseEntity.getCreateUser();
Long createDept = baseEntity.getCreateDept();
if (FuncBase.isNotEmpty(current)) {
baseEntity.setCreateTime(current);
if (FuncBase.isNotEmpty(current)) {
baseEntity.setCreateTime(current);
}
if (FuncBase.isNotEmpty(userId) && FuncBase.isEmpty(createUser)) {
baseEntity.setCreateUser(userId);
}
if (FuncBase.isNotEmpty(deptId) && FuncBase.isEmpty(createDept)) {
baseEntity.setCreateDept(deptId);
}
}
if (FuncBase.isNotEmpty(userId) && FuncBase.isEmpty(createUser)) {
baseEntity.setCreateUser(userId);
}
if (FuncBase.isNotEmpty(deptId) && FuncBase.isEmpty(createDept)) {
baseEntity.setCreateDept(deptId);
if (obj instanceof BaseTenantEntity) {//我们自定义的实体
BaseTenantEntity baseEntity = (BaseTenantEntity) obj;
Long selectTenantId = baseEntity.getTenantId();
if (FuncBase.isEmpty(selectTenantId) && FuncBase.isNotEmpty(tenantId)) {
baseEntity.setTenantId(tenantId);
}
}
})).get();
} catch (InterruptedException | ExecutionException e){
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
if (obj instanceof BaseTenantEntity) {//我们自定义的实体
BaseTenantEntity baseEntity = (BaseTenantEntity) obj;
Long selectTenantId = baseEntity.getTenantId();
if (FuncBase.isEmpty(selectTenantId) && FuncBase.isNotEmpty(tenantId)) {
baseEntity.setTenantId(tenantId);
}
}
})).get();
}
}
// plus新增修改
@@ -269,7 +281,7 @@ public class DefaultValAspect {
}
// plus批量新增修改
private void saveOrUpdateBatchPlus(Object[] args) throws Throwable {
private void saveOrUpdateBatchPlus(Object[] args) {
List list = (List) args[0];
Object o = list.get(0);
if (!(o instanceof BaseEntity || o instanceof BaseTenantEntity)) {//不属于我们的类型
@@ -281,41 +293,51 @@ public class DefaultValAspect {
Long tenantId = proxyAdapter.getTenantId();
Long deptId = proxyAdapter.getOnlineUserDeptId();
FuncBase.jeelowcodeForkJoinPool().submit(() -> list.parallelStream().forEach(obj -> {
//基本类
if (obj instanceof BaseEntity) {//我们自定义的实体
BaseEntity baseEntity = (BaseEntity) obj;
if (FuncBase.isEmpty(baseEntity.getId())) {
Long createUser = baseEntity.getCreateUser();
Long createDept = baseEntity.getCreateDept();
if (FuncBase.isNotEmpty(current)) {
baseEntity.setCreateTime(current);
}
if (FuncBase.isNotEmpty(userId) && FuncBase.isEmpty(createUser)) {
baseEntity.setCreateUser(userId);
}
if (FuncBase.isNotEmpty(deptId) && FuncBase.isEmpty(createDept)) {
baseEntity.setCreateDept(deptId);
}
} else {
baseEntity.setUpdateTime(current);
if (FuncBase.isEmpty(baseEntity.getUpdateUser()) && FuncBase.isNotEmpty(userId)) {
baseEntity.setUpdateUser(userId);
ForkJoinPool pool = null;
try {
pool = FuncBase.jeelowcodeForkJoinPool();
pool.submit(() -> list.parallelStream().forEach(obj -> {
//基本类
if (obj instanceof BaseEntity) {//我们自定义的实体
BaseEntity baseEntity = (BaseEntity) obj;
if (FuncBase.isEmpty(baseEntity.getId())) {
Long createUser = baseEntity.getCreateUser();
Long createDept = baseEntity.getCreateDept();
if (FuncBase.isNotEmpty(current)) {
baseEntity.setCreateTime(current);
}
if (FuncBase.isNotEmpty(userId) && FuncBase.isEmpty(createUser)) {
baseEntity.setCreateUser(userId);
}
if (FuncBase.isNotEmpty(deptId) && FuncBase.isEmpty(createDept)) {
baseEntity.setCreateDept(deptId);
}
} else {
baseEntity.setUpdateTime(current);
if (FuncBase.isEmpty(baseEntity.getUpdateUser()) && FuncBase.isNotEmpty(userId)) {
baseEntity.setUpdateUser(userId);
}
}
}
}
if (obj instanceof BaseTenantEntity) {//我们自定义的实体
BaseTenantEntity baseEntity = (BaseTenantEntity) obj;
if (FuncBase.isNotEmpty(baseEntity.getId())){
return;
}
Long selectTenantId = baseEntity.getTenantId();
if (FuncBase.isEmpty(selectTenantId) && FuncBase.isNotEmpty(tenantId)) {
baseEntity.setTenantId(tenantId);
if (obj instanceof BaseTenantEntity) {//我们自定义的实体
BaseTenantEntity baseEntity = (BaseTenantEntity) obj;
if (FuncBase.isNotEmpty(baseEntity.getId())){
return;
}
Long selectTenantId = baseEntity.getTenantId();
if (FuncBase.isEmpty(selectTenantId) && FuncBase.isNotEmpty(tenantId)) {
baseEntity.setTenantId(tenantId);
}
}
})).get();
} catch (InterruptedException | ExecutionException e){
throw new RuntimeException(e.getMessage());
} finally {
if (pool != null) {
pool.shutdown();
}
})).get();
}
}
//编辑