异步处理MultipartFile No such file or directory的分析
背景
项目中开发导入功能,因为数据量比较大,所以要求后端异步操作。发现改为异步之后,相同代码的情况下会报(No such file or directory)异常
2020-02-28 16:22:51.322 [pool-2-thread-1] ERROR c.c.l.m.business.service.impl.CommonServiceImpl - /private/var/folders/gj/_gbl0m854pn1lw6dn2k4w1gr0000gn/T/tomcat.5469750062936240832.8081/work/Tomcat/localhost/lm-admin/upload_bc9f994f_f4dc_4a2e_9933_dbcec37b3a7e_00000001.tmp (No such file or directory)
com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.45, class org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:465)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:120)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:280)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:673)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:611)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:576)
at com.citi.lm.modules.business.service.impl.CommonServiceImpl.readAndHandleFile(CommonServiceImpl.java:93)
at com.citi.lm.modules.business.service.impl.CommonServiceImpl$$FastClassBySpringCGLIB$$82c8f695.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
at com.citi.lm.modules.business.service.impl.CommonServiceImpl$$EnhancerBySpringCGLIB$$5f90c28f.readAndHandleFile(<generated>)
at com.citi.lm.modules.business.controller.CommonController$1.call(CommonController.java:84)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.alibaba.fastjson.util.FieldInfo.get(FieldInfo.java:484)
at com.alibaba.fastjson.serializer.FieldSerializer.getPropertyValueDirect(FieldSerializer.java:135)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:249)
... 16 more
Caused by: java.io.FileNotFoundException: /private/var/folders/gj/_gbl0m854pn1lw6dn2k4w1gr0000gn/T/tomcat.5469750062936240832.8081/work/Tomcat/localhost/lm-admin/upload_bc9f994f_f4dc_4a2e_9933_dbcec37b3a7e_00000001.tmp (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.getInputStream(DiskFileItem.java:194)
at org.apache.catalina.core.ApplicationPart.getInputStream(ApplicationPart.java:100)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile.getBytes(StandardMultipartHttpServletRequest.java:245)
... 23 more
纠错
不啰嗦过程,最后将焦点集中在接口接收的MultipartFile类型参数上。debug跟踪MultipartFile类型参数发现,在主线程结束响应之后,MultipartFile类型参数就消失了。


分析
说明在响应结束之后,file的内存区域被清除回收了,和servlet规范一致。个人理解,file参数对象就像servlet的request和response对象一样,请求一结束就被清理了。
解决
目前没有解决办法,因为后来项目需求把接收的文件保存下来,那么对我来说就不是问题了。但是我想可以在创建处理线程之前把file中的二进制流转成其他形式保留下来,然后对新保留的数据进行处理。
参考:https://blog.csdn.net/yinni11/article/details/83793930
异步处理MultipartFile No such file or directory的分析的更多相关文章
- sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分析:这是不同系统编码格式引起的:在windows系统中 ...
- sh脚本异常:bad interpreter: No such file or directory
转:http://bluedest.iteye.com/blog/1674963 在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file o ...
- hadoop问题: bin/hadoop fs -ls ls: `.': No such file or directory
问题描述:bin/hadoop fs -ls ls: `.': No such file or directory 问题分析:版本问题,用法不同 https://stackoverflow.com/q ...
- Linux中运行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory。
在Linux中运行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分析:这是不同系统编码格式引起的:在windows系统中 ...
- mac下/usr/local/bin No such file or directory问题解决
在对composer进行全局配置时,执行 sudo mv composer.phar /usr/local/bin/composer 时,mac报错:/usr/local/bin No such fi ...
- troubleshooting-执行导数shell脚本抛异常error=2, No such file or directory
Cannot run program "order_log.sh" (in directory "/data/yarn/nm/usercache/chenweidong/ ...
- [shell编程] sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory
转载地址:http://www.cnblogs.com/pipelone/archive/2009/04/17/1437879.html 在Linux中执行.sh脚本,异常/bin/sh^M: bad ...
- nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
测试服务器 问题描述 [root@g-s-- nginx]# /usr/sbin/nginx -c /etc/nginx/nginx.conf open() : No such file or dir ...
- Git异常:fatal: could not create work tree dir 'XXX': No such file or directory
GitHub实战系列汇总:http://www.cnblogs.com/dunitian/p/5038719.html ———————————————————————————————————————— ...
随机推荐
- POI导出excel的三种方式
原文链接:https://www.cnblogs.com/zhaoblog/p/7661245.html poi导出excel最常用的是第一种方式HSSFWorkbook,不过这种方式数据量大的话会产 ...
- laravel 初学路由简单介绍
文档中的路由详细演示[初学laravel]对应laravel 的框架目录:routes/web.php 路由的格式一:Route::get($uri,$callback); 1.简单的浏览器输出 Ro ...
- hashlib 模块的用法
import hashlib #多用于加密a=hashlib.md5()print(a) #<md5 HASH object @ 0x00000000021CCF90> a.update( ...
- this和static
[this] 指的是明确的标记本类的结构 当前正在调用类中方法的对象,不是一个固定的 java中以“{}”为界限.如果现在属性名称和参数名称重名,那么默认情况下,如果没有加任何的限制,指的是最近的“{ ...
- FFMPEG学习----使用SDL构建音频播放器
ffmpeg版本:ffmpeg-20160413-git-0efafc5 #include <stdio.h> #include <stdlib.h> #include < ...
- WeChall_Prime Factory (Training, Math)
Your task is simple:Find the first two primes above 1 million, whose separate digit sums are also pr ...
- POJ 1789 Truck History (Kruskal最小生成树) 模板题
Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for v ...
- API 接口设计规范
概述 这篇文章分享 API 接口设计规范,目的是提供给研发人员做参考. 规范是死的,人是活的,希望自己定的规范,不要被打脸. 路由命名规范 动作 前缀 备注 获取 get get{XXX} 获取 ge ...
- 全局new和宏结合起来的一个小应用
#include <iostream> using namespace std; void* operator new(size_t size, const char* file, int ...
- 2020-02-19Linux学习日记,第一天
今天是2020-02-19第一次写博客.每天更新学习Linux的一些笔记. 主要是为了方便日后自己复习,也是为了督促自己学习.记录自己的学习轨迹! -------------------------- ...