编程语言
首页 > 编程语言> > java多綫程

java多綫程

作者:互联网

ExecutorService threadPool = Executors.newFixedThreadPool(6);

List<AppDocFileUploadDto> files = fileUploadDto.getDocumentlist();

List<CompletableFuture<Void>> result = files.stream().map(fileDto ->
                    CompletableFuture.runAsync(
                            new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        String folderName = fileDto.getFileType();
                                        
                                        synchronized (folderName.intern()) {
                                            if (folderIds.isEmpty() || !folderIds.containsKey(folderName)) {
                                                WSFolder wsFolder = dmsExpService.createAppSubTypeFolder(sid, folderName, targetFolder.getId(), wsAttributes);
                                                folderIds.put(folderName, wsFolder.getId());
                                            }
                                        }
                                        String filePath = fileDto.getPath();
                                        MultipartFile file = null;
                                       
                                        dmsExpService.uploadWithAttributes(sid, file.getOriginalFilename(), folderIds.get(folderName), file, template.getId(),
                                                wsAttributes == null ? null : wsAttributes, loanEntry);

                                    } catch (Exception e) {
                                        logger.info("kafka send file to dms error , file : {} ,  {},", fileDto, e.getMessage());
                                    }
                                }
                            }
                    ,threadPool)).collect(Collectors.toList());

// 執行:

            result.stream().forEach(e-> {
                try {
                    e.get();
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                } catch (ExecutionException ex) {
                    ex.printStackTrace();
                }
            });

  

标签:folderIds,java,fileDto,folderName,ex,file,catch
来源: https://www.cnblogs.com/z360519549/p/16292550.html