zoukankan      html  css  js  c++  java
  • 记录一下 spring boot 线程处理返回数据

    @Api
    @Controller
    public class FileController {
    
    
        private final static ExecutorService executor = Executors.newFixedThreadPool(2);
        private static Logger logger = LoggerFactory.getLogger(FileController.class);
    
        @Autowired
        private FileService fileService;
    
    
        @PostMapping("/uploadFile")
        @ApiResponse
        @ApiOperation(value = "上传文件", httpMethod = "POST")
        @PassToken
        public FileResponse uploadFile(@RequestParam("file") MultipartFile multipartFile) throws ApiException {
    
            FileResponse fileResponse = new FileResponse();
            fileResponse.setFilepath(fileService.uploadFile(multipartFile));
            return fileResponse;
    
        }
    
    
        @PostMapping("/uploadVideoFile")
        @ApiResponse
        @ApiOperation(value = "上传文件", httpMethod = "POST")
        @PassToken
        public FileResponse uploadVideoFile(@RequestParam("file") MultipartFile multipartFile) throws Exception {
    
            FileResponse fileResponse = new FileResponse();
    
            final CountDownLatch end = new CountDownLatch(2);
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        fileResponse.setFilepath(fileService.uploadFile(multipartFile));
                    }  catch(Exception e){
                        fileResponse.setFilepath(null);
                        logger.error(e.getMessage());
                    }finally{
                        end.countDown();
                    }
    
                }
    
            });
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        fileResponse.setVideFilePath(fileService.cutImage(multipartFile, 1));
                    } catch (Exception e) {
                        fileResponse.setVideFilePath(null);
                        logger.error(e.getMessage());
                    } finally {
                        end.countDown();
                    }
    
                }
    
            });
            end.await();
            return fileResponse;
        }
    
    
    程序开发机器人 琴酒、灰原哀、刺痛是我心尖尖上的人 最爱琴酒、灰原哀、刺痛
  • 相关阅读:
    解决mysqldump: Got error: 1044: Access denied for user
    Ubuntu技巧之 is not in the sudoers file解决方法
    mysql日志详细解析
    linux利用grep查看打印匹配的下几行或前后几行的命令
    Linux无法使用userdel删除用户和组的解决办法
    ubuntu快速清理磁盘垃圾
    smarty中math函数的用法
    metinfo首页内容简介
    linux命令别名的使用
    mysql 导出表结构和表数据 mysqldump用法
  • 原文地址:https://www.cnblogs.com/doudou0809/p/13949509.html
Copyright © 2011-2022 走看看