【JAVA】关于项目中的异步文件上传问题

【JAVA】关于项目中的异步文件上传问题

1.问题:
项目中客户文件上传请求过程http请求等待时间太长,考虑将文件业务处理部分采用异步方式实现,整个异步部分封装原先文件处理的业务逻辑,主线程及时返回客户上传请求结果.

请求示例:
在这里插入图片描述
2.原本代码:

    /**
     * 文件上传
     *
     * @param file
     * @param paramStr Param
     * @return
     */
    @PostMapping("/fileAsyncUploadServlet")
    //文件接收:MultipartFile
	//JSON接收:String
    public String upload(@RequestParam("file") MultipartFile file, @RequestParam("param") String paramStr) {
   

	//参数校验业务逻辑...
	
	//调用文件处理方法(文件分析处理,上传云服务器等)...
	
	return result;
	
}	

3.更新代码:

//主启动类
@EnableAsync

//异步方法(文件处理)
@Async

//修改application.yaml
spring:
  async:
    core:
      pool:
        size: 5
    max:
      pool:
        size: 50
    queue:
      capacity: 500
//注:线程池参数设置技巧
//http://www.imooc.com/article/5887
      
package com.aisp.quality.check.config;

import java.util.concurrent.Executor;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值