Preface:
2003~
problem description:
existing store Id collection [List < Integer >], and execute static method [staticizeIndexBySubsite (Integer subId)], want to open 3 threads to let staticizeIndexBySubsite method consume store collection List, entry time is short plus construction period is urgent, inexperienced I can"t think of a thread-safe solution at a time, so I can only go here to find out:)
Code:
public synchronized void staticizeIndexBySubsites(List<Integer> subsiteIds) {
if(CollectionUtils.isNotEmpty(subsiteIds)){
for(Integer id : subsiteIds){
//
staticizeIndexBySubsite(id);
}
}
}
@Override
public void staticizeIndexBySubsite(Integer subsiteId) {
if(NumberUtils.isEmpty(subsiteId)) return;
try{
Boolean ischinese;
OverSeaHomeVO overSeaHomeVO;
HomeNewVO homeNewVO;
HomeNewVO wxHomeNewVO;
String fileName;
for(int y = 0 ; y<language.length;yPP){
ischinese = language[y];
fileName = subsiteId+"-"+(language[y]==true?"zh-CN":"en")+".json";
try {
SubsiteDTO subsiteDTO = subSiteService.get(subsiteId);
if(subsiteDTO != null && subsiteDTO.getStatus() == 1){
if(subsiteDTO.isIsGlobal()){//
overSeaHomeVO = mobileStaticIndexService.getOverseaIndexBySubsite(subsiteId, ischinese, MultipleChannelsConstants.IOS_CHANNEL);
if(overSeaHomeVO != null){
writeAppIndex(successResult(overSeaHomeVO),parentRealPath,fileName);
writeAppIndex(successResult(overSeaHomeVO),wechatIndexReaPath,fileName);
}
}else{//
homeNewVO = mobileStaticIndexService.getHomeNewBySubsite(MobileSiteStructureIdsConstant.MOBILE_NEW_SITE_STRUCTURE_ID_HOME, subsiteId, ischinese, MultipleChannelsConstants.IOS_CHANNEL);
if(homeNewVO != null){
writeAppIndex(successResult(homeNewVO),parentRealPath,fileName);
}
//
wxHomeNewVO = mobileStaticIndexService.getHomeNewBySubsite(MobileSiteStructureIdsConstant.MOBILE_SITE_STRUCTURE_ID_WX_HOME, subsiteId, ischinese, MultipleChannelsConstants.WEIXIN_CHANNEL);
if(wxHomeNewVO != null){
writeAppIndex(successResult(wxHomeNewVO),wechatIndexReaPath,fileName);
}
}
}
} catch (Exception e) {
e.printStackTrace();
log.error("MobileStaticIndexProcess error" + subsiteId+"***"+ischinese);
}
}
}catch(Exception e){
e.printStackTrace();
log.error("json"+e.fillInStackTrace());
}
}