目录
前言描述:
主要是执行线程进行同步,简单的一个线程,后来废弃掉了,所以代码备份到这里
主要得线程代码
@Data
private class SendCorpusRunnable implements Runnable {
private Long newsId;
private List<TbmPopularFeelings> eventInfoList;
private Map<Long, List<TbmEventTags>> eventTagsMap;
public SendCorpusRunnable(Long newsId, List<TbmPopularFeelings> eventInfoList,
Map<Long, List<TbmEventTags>> eventTagsMap) {
this.newsId = newsId;
this.eventInfoList = eventInfoList;
this.eventTagsMap = eventTagsMap;
}
@Override
public void run() {
try {
NewsEventVo newsEventVo = TbmEventConvert.convertToCorpus(newsId, eventInfoList, eventTagsMap);
newsEventFacade.save(newsEventVo);
} catch (CorpusException e) {
e.printStackTrace();
}
}
}
测试的地方里面的方法体进行的逻辑处理
/**
* 转换推送语料数据
*
* @param eventInfoList
* @return
*/
public static NewsEventVo convertToCorpus(Long newsId, List<TbmPopularFeelings> eventInfoList, Map<Long, List<TbmEventTags>> eventTagsMap) {
NewsEventVo newsEventVo = new NewsEventVo();
newsEventVo.setNewsId(newsId);
if (CollectionUtils.isEmpty(eventInfoList)) {
return newsEventVo;
}
List<NewsEventVo.EventCalloutVo> eventCalloutVoList = new ArrayList<>();
eventInfoList.forEach(eventInfo -> {
NewsEventVo.EventCalloutVo eventCalloutVo = new NewsEventVo.EventCalloutVo();
if (StringUtils.isNotBlank(eventInfo.getEventFourthLevelCode())) {
eventCalloutVo.setEventCode(eventInfo.getEventFourthLevelCode());
}
if (StringUtils.isNotBlank(eventInfo.getEventFourthLevel())) {
eventCalloutVo.setEventName(eventInfo.getEventFourthLevel());
}
if (StringUtils.isNotBlank(eventInfo.getEventBasis())) {
eventCalloutVo.setEventBasis(eventInfo.getEventBasis());
}
//提取标签主体
List<TbmEventTags> eventTagList = eventTagsMap.get(eventInfo.getId());
List<NewsEventVo.EventSubjectVo> subjectList = new ArrayList<>();
if (!CollectionUtils.isEmpty(eventTagList)) {
eventTagList.forEach(eventTag -> {
NewsEventVo.EventSubjectVo eventSubjectVo = new NewsEventVo.EventSubjectVo();
eventSubjectVo.setSubjectName(eventTag.getTagName());
if (StringUtils.isNotBlank(eventTag.getMainBasis())) {
eventSubjectVo.setSubjectBasis(eventTag.getMainBasis());
}
subjectList.add(eventSubjectVo);
});
}
eventCalloutVo.setSubjectList(subjectList);
eventCalloutVoList.add(eventCalloutVo);
});
newsEventVo.setEventList(eventCalloutVoList);
return newsEventVo;
}
调用的时候:
// 发送语料平台,异步
ThreadPoolExecutor threadPoolExecutor = ThreadPoolExecutorFactory.getThreadPoolExecutor();
threadPoolExecutor.submit(new SendCorpusRunnable(newsId, tbmPopularFeelingsList, eventTagsMap));
// 发送语料平台,异步
ThreadPoolExecutor threadPoolExecutor = ThreadPoolExecutorFactory.getThreadPoolExecutor();
threadPoolExecutor.submit(new SendCorpusRunnable(newsId, tbmPopularFeelingsList, eventTagsMap));