子线程测试

This commit is contained in:
wulin 2020-11-18 15:05:34 +08:00
parent 5b9376d3b7
commit 3d962752bd
2 changed files with 9 additions and 3 deletions

View File

@ -103,7 +103,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
@Autowired @Autowired
private DingtalkBusiness dingtalkBusiness; private DingtalkBusiness dingtalkBusiness;
List<ThreadInitFlowRecord> threads = new ArrayList<>(); List<ThreadInitFlowRecord> threadInitFlowRecords = new ArrayList<>();
@ -811,9 +811,10 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
private void initFlowRecordAnsy(List<ResultRecord> resultRecords, List<StaffSimpleInfo> noticeStaff){ private void initFlowRecordAnsy(List<ResultRecord> resultRecords, List<StaffSimpleInfo> noticeStaff){
if(resultRecords.size() > 0){ if(resultRecords.size() > 0){
ThreadInitFlowRecord threadInitFlowRecord = new ThreadInitFlowRecord(resultRecords, noticeStaff); ThreadInitFlowRecord threadInitFlowRecord = new ThreadInitFlowRecord(resultRecords, noticeStaff);
threadInitFlowRecords.add(threadInitFlowRecord);//防止提前回收
Thread thread = new Thread(threadInitFlowRecord); Thread thread = new Thread(threadInitFlowRecord);
thread.start(); thread.start();
threads.add(threadInitFlowRecord);
} }
} }
@ -841,7 +842,7 @@ public class FlowStartServiceImpl extends ServiceImpl<FlowStartMapper, FlowStart
} }
//ch.qos.logback.classic.Logger.threadLocalNo.set(oldNo); //ch.qos.logback.classic.Logger.threadLocalNo.set(oldNo);
dingtalkBusiness.sendWorkMSGWithAsyn(noticeStaff, WorkMsgTypeEnum.START_WORK.getType()); dingtalkBusiness.sendWorkMSGWithAsyn(noticeStaff, WorkMsgTypeEnum.START_WORK.getType());
threads.remove(this); threadInitFlowRecords.remove(this);
} }
} }
} }

View File

@ -77,6 +77,8 @@ public class DingtalkBusiness {
@Resource @Resource
StaffDao staffDao; StaffDao staffDao;
List<ThreadSendMessage> threadSendMessages = new ArrayList<>();
@Value("${dingtalk.appid}") @Value("${dingtalk.appid}")
private String appid; private String appid;
@ -257,8 +259,10 @@ public class DingtalkBusiness {
WorkMsgTypeEnum workMsgTypeEnum = WorkMsgTypeEnum.findRoleTypeByCode(type); WorkMsgTypeEnum workMsgTypeEnum = WorkMsgTypeEnum.findRoleTypeByCode(type);
ThreadSendMessage threadSendMessage = new ThreadSendMessage(fromStaff, toStaffids, workMsgTypeEnum, appid); ThreadSendMessage threadSendMessage = new ThreadSendMessage(fromStaff, toStaffids, workMsgTypeEnum, appid);
threadSendMessages.add(threadSendMessage);//防止提前回收
Thread thread = new Thread(threadSendMessage); Thread thread = new Thread(threadSendMessage);
thread.start(); thread.start();
return "OK"; return "OK";
} }
return "error"; return "error";
@ -391,6 +395,7 @@ public class DingtalkBusiness {
logger.info("ThreadSendMessage token无效"); ; logger.info("ThreadSendMessage token无效"); ;
} }
} }
threadSendMessages.remove(this);
} }
} }
} }