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

update:构建批次缓存清理调整

上级 94b52b8b
...@@ -17,4 +17,6 @@ public interface BaseEntityService { ...@@ -17,4 +17,6 @@ public interface BaseEntityService {
ExecLog processAll(BaseRequest msg); ExecLog processAll(BaseRequest msg);
void saveResult(ModelObj param, String RULEID, String RULECODE, String RULENAME, String RU_EXECRESULTNAME, FieldObj BUSINESSCAT, Integer RETVALUE, FieldObj KEYVALUEFIELD, FieldObj DOMAINSFIELD, FieldObj DIMFIELD, 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); FieldObj METRICFIELD, FieldObj TIMEFIELD, FieldObj EXT1FIELD, FieldObj EXT2FIELD);
void cleanKieContainer();
void cleanExpirationKieContainer();
} }
\ No newline at end of file
...@@ -643,37 +643,75 @@ public class BaseEntityServiceImpl implements BaseEntityService ...@@ -643,37 +643,75 @@ public class BaseEntityServiceImpl implements BaseEntityService
/** /**
* 清理过期的KieContainer,默认超过七天即认为过期失效 * 清理过期的KieContainer,默认超过七天即认为过期失效
*/ */
public void cleanExpirationKieContainer() throws ParseException { @Override
int beforeSize = setKc.size(); public void cleanExpirationKieContainer(){
if (setKc.size() > 0){ int beforeSize = this.setKc.size();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); if (beforeSize == 0){
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); return;
long curTime = simpleDateFormat2.parse(LocalDate.now().toString()).getTime(); }
long timeDifference = this.expirationDays * 24 * 60 * 60 * 1000; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
Iterator<String> iterator = setKc.keySet().iterator(); SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
while (iterator.hasNext()) { long curTime = 0L;
// 构建批次信息,如:20230214140921[高检-信访辅助(规则专用)]-cnt-10 try {
String bacth = iterator.next(); curTime = simpleDateFormat2.parse(LocalDate.now().toString()).getTime();
if (!StringUtils.isEmpty(bacth) && bacth.length() > 8){ } catch (ParseException e) {
try{ e.printStackTrace();
String strBatchTime = bacth.substring(0,8); log.error(String.format("获取当前日期时间戳异常,原因:",e.getMessage()));
long batchTime = simpleDateFormat.parse(strBatchTime).getTime(); return;
if ((curTime - batchTime) > timeDifference){ }
iterator.remove(); long timeDifference = this.expirationDays * 24 * 60 * 60 * 1000;
log.info(String.format("[batch]:%1$s,是否被清除:是",bacth)); Iterator<String> iterator = this.setKc.keySet().iterator();
}else { while (iterator.hasNext()) {
log.info(String.format("[batch]:%1$s,是否被清除:否",bacth)); // 构建批次信息,如: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){
try{
this.setKc.get(bacth).dispose();
}catch (Exception ex){
ex.printStackTrace();
log.error(String.format("setKc.get(iterator).dispose()异常,原因:" + ex.getMessage()));
} }
}catch (Exception e){ iterator.remove();
e.printStackTrace(); log.info(String.format("[batch]:%1$s,是否被清除:是",bacth));
log.error(String.format("比较构建批次[batch]:%1$s,是否过期异常,原因:%2$s",bacth,e.getMessage())); }else {
} 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(); int afterSize = this.setKc.size();
log.info(String.format("清理过期setKc完成,过期时间(天):%1$s,清理前setKc大小:%2$s,清理后setKc大小:%3$s,清理setKc数:%4$s",this.expirationDays,beforeSize,afterSize,(beforeSize - afterSize) )); log.info(String.format("清理过期setKc完成,过期时间(天):%1$s,清理前setKc大小:%2$s,清理后setKc大小:%3$s,清理setKc数:%4$s",this.expirationDays,beforeSize,afterSize,(beforeSize - afterSize) ));
} }
@Override
public void cleanKieContainer() {
int beforeSize = this.setKc.size();
if (beforeSize == 0){
return;
}
Iterator<String> iterator = this.setKc.keySet().iterator();
while (iterator.hasNext()) {
// 构建批次信息,如:20230214140921[高检-信访辅助(规则专用)]-cnt-10
String bacth = iterator.next();
try{
this.setKc.get(bacth).dispose();
}catch (Exception ex){
ex.printStackTrace();
log.error(String.format("--cleanKieContainer--setKc.get(iterator).dispose()异常,[batch]:%1$s,原因:%2$s" ,bacth,ex.getMessage()));
}
iterator.remove();
log.info(String.format("--cleanKieContainer--[batch]:%1$s,已被清除。",bacth));
}
int afterSize = this.setKc.size();
log.info(String.format("--cleanKieContainer--执行完成,清理前setKc大小:%1$s,清理后setKc大小:%2$s,清理setKc数:%3$s",beforeSize,afterSize,(beforeSize - afterSize) ));
}
} }
\ No newline at end of file
...@@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker; ...@@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
...@@ -80,6 +81,10 @@ public class RuleEngineExService extends RuleEngineServiceImpl { ...@@ -80,6 +81,10 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
@Autowired @Autowired
private ExecResultExService execResultExService; private ExecResultExService execResultExService;
@Autowired
@Qualifier("AnalyseEntityServiceImpl")
private BaseEntityService analyseEntityServiceImpl;
/** /**
* [Run:运行] 行为扩展 * [Run:运行] 行为扩展
* @param et * @param et
...@@ -347,5 +352,12 @@ public class RuleEngineExService extends RuleEngineServiceImpl { ...@@ -347,5 +352,12 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
} }
return super.check(et); return super.check(et);
} }
@Override
public RuleEngine cleanKC(RuleEngine et) {
baseEntityService.cleanKieContainer();
analyseEntityServiceImpl.cleanKieContainer();
return et;
}
} }
package cn.ibizlab.core.util.job; package cn.ibizlab.core.util.job;
import cn.ibizlab.core.extensions.service.BaseEntityServiceImpl; import cn.ibizlab.core.extensions.service.BaseEntityService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -18,7 +19,11 @@ public class CleanExpirationKieContainerJobHandler { ...@@ -18,7 +19,11 @@ public class CleanExpirationKieContainerJobHandler {
@Autowired @Autowired
@Lazy @Lazy
private BaseEntityServiceImpl baseEntityService; private BaseEntityService baseEntityService;
@Autowired
@Lazy
@Qualifier("AnalyseEntityServiceImpl")
private BaseEntityService analyseEntityServiceImpl;
/** /**
* 默认每天凌晨6点开始执行 * 默认每天凌晨6点开始执行
...@@ -29,6 +34,7 @@ public class CleanExpirationKieContainerJobHandler { ...@@ -29,6 +34,7 @@ public class CleanExpirationKieContainerJobHandler {
log.info("--cleanExpirationKieContainer--开始执行"); log.info("--cleanExpirationKieContainer--开始执行");
try { try {
baseEntityService.cleanExpirationKieContainer(); baseEntityService.cleanExpirationKieContainer();
analyseEntityServiceImpl.cleanExpirationKieContainer();
log.info("--cleanExpirationKieContainer--执行完成,耗时(毫秒):" + (System.currentTimeMillis() - start)); log.info("--cleanExpirationKieContainer--执行完成,耗时(毫秒):" + (System.currentTimeMillis() - start));
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册