51,412
社区成员
发帖
与我相关
我的任务
分享
定时器中方法
//创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
for (final FileDownBy fdb : fdbList) {
fixedThreadPool.execute(new Runnable() {
public void run() {
try {
downAndSynDataService.modifyData(fdb);
} catch (Exception e) {
e.printStackTrace();
}
}//run
});//fixedThreadPool
}//for
实现类中方法
public void modifyData(FileDownBy fdb){
try{
String name=UUIDGenerator.getUUID();
FileDownTo fdt =new FileDownTo();
int exists=1;//附件是否存在 0否 1是
if(fdb.getFileType().equals("附件")){
String suffix=fdb.getFileurl().substring(fdb.getFileurl().lastIndexOf(".")+1);
String httpurl=toFastDfs(fdb.getFileurl(), suffix);//上传文件服务器
System.out.println(httpurl);
if(existHttpPath(httpurl)){
fdt.setHttpurl(name+"."+suffix);
fdt.setLocalurl(httpurl);
fdt.setSuffix(suffix);
}else{
exists=0;
}
}
if(exists==1){
fdt.setByid(fdb.getId());
fdt.setCreateDate(new Date());
commonDao.save(fdt);
fdb.setUpdatetime(new Date());
fdb.setIsDown(1);
fdb.setCount((null==fdb.getCount()||"".equals(fdb.getCount())||fdb.getCount()==0)?1:fdb.getCount()+1);
commonDao.update(fdb);
addFileAttach(fdt,fdb,fdb.getFilename());//附件信息表导入FileAtach
addInfoPersonal(fdb.getId());//导入其他系统附件传入信息记录(附件的主表信息)
addInfoFilePremissions(fdb.getId());//导入其他系统附件传入信息记录表(附件的使用权限信息)
}else{
log.info("该附件不存在!");
}
}catch(Exception e){
updateFdbCount(fdb);//修改下载次数
log.info("下载失败:"+fdb.getFilename()+" -"+e.getMessage());
}