提交 d022246d 编写于 作者: xuhui961310148's avatar xuhui961310148

add:添加定时任务,清除构建批次缓存,解决dst内存高

上级 5e1352de
......@@ -35,10 +35,10 @@ import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
/**
* 规则服务对象接口
......@@ -64,6 +64,8 @@ public class BaseEntityServiceImpl implements BaseEntityService
@Value("${defaultResultTableName:IBZRULERESULT}")
protected String Default_ResultTableName;
@Value("${ibiz.expirationDays:7}")
protected int expirationDays;
public void saveResult(ModelObj param, String RULEID,String RULECODE, String RULENAME, String RU_EXECRESULTNAME, FieldObj BUSINESSCAT, Integer RETVALUE, FieldObj KEYVALUEFIELD, FieldObj DOMAINSFIELD,FieldObj DIMFIELD,
FieldObj METRICFIELD, FieldObj TIMEFIELD, FieldObj EXT1FIELD, FieldObj EXT2FIELD)
......@@ -637,4 +639,41 @@ public class BaseEntityServiceImpl implements BaseEntityService
return codeList;
}
/**
* 清理过期的KieContainer,默认超过七天即认为过期失效
*/
public void cleanExpirationKieContainer() throws ParseException {
int beforeSize = setKc.size();
if (setKc.size() > 0){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
long curTime = simpleDateFormat2.parse(LocalDate.now().toString()).getTime();
long timeDifference = this.expirationDays * 24 * 60 * 60 * 1000;
Iterator<String> iterator = setKc.keySet().iterator();
while (iterator.hasNext()) {
// 构建批次信息,如:20230214140921[高检-信访辅助(规则专用)]-cnt-10
String bacth = iterator.next();
if (!StringUtils.isEmpty(bacth) && bacth.length() > 8){
try{
String strBatchTime = bacth.substring(0,8);
long batchTime = simpleDateFormat.parse(strBatchTime).getTime();
if ((curTime - batchTime) > timeDifference){
iterator.remove();
log.info(String.format("[batch]:%1$s,是否被清除:是",bacth));
}else {
log.info(String.format("[batch]:%1$s,是否被清除:否",bacth));
}
}catch (Exception e){
e.printStackTrace();
log.error(String.format("比较构建批次[batch]:%1$s,是否过期异常,原因:%2$s",bacth,e.getMessage()));
}
}else {
log.info(String.format("[batch]:%1$s,是否被清除:否",bacth));
}
}
}
int afterSize = setKc.size();
log.info(String.format("清理过期setKc完成,过期时间(天):%1$s,清理前setKc大小:%2$s,清理后setKc大小:%3$s,清理setKc数:%4$s",this.expirationDays,beforeSize,afterSize,(beforeSize - afterSize) ));
}
}
\ No newline at end of file
package cn.ibizlab.core.util.job;
import cn.ibizlab.core.extensions.service.BaseEntityServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* 清理引擎、报表构建时,产生的全局无效KieContainer
*/
@Slf4j
@Component("CleanExpirationKieContainerJobHandler")
@ConditionalOnExpression("${ibiz.isCleanKC:false}")
public class CleanExpirationKieContainerJobHandler {
@Autowired
@Lazy
private BaseEntityServiceImpl baseEntityService;
/**
* 默认每天凌晨6点开始执行
*/
@Scheduled(cron = "${ibiz.cleanCronValue:0 0 6 * * ?}")
private void cleanExpirationKieContainer(){
long start = System.currentTimeMillis();
log.info("--cleanExpirationKieContainer--开始执行");
try {
baseEntityService.cleanExpirationKieContainer();
log.info("--cleanExpirationKieContainer--执行完成,耗时(毫秒):" + (System.currentTimeMillis() - start));
}catch (Exception e){
e.printStackTrace();
log.error("--cleanExpirationKieContainer--执行异常,原因:" + e.getMessage());
}
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册