异步处理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 ———————————————————————————————————————— ...
随机推荐
- Oracle:imp导入dmp文件
oracle命令行登录 sqlplus / as sysdba 创建用户 create user 用户 identified by 密码 ; 创建表空间 create tablespace 表空间名 ...
- 安装Eclipse activity插件 报异常 Cannot complete the install because one or more required items could not be
下载插件:Activiti Designer 5.17 2)安装过程中错误处理 a.错误: Cannot complete the install because one or more requir ...
- 编译调试 .NET Core 5.0 Preview 并分析 Span 的实现原理
很久没有写过 .NET Core 相关的文章了,目前关店在家休息所以有些时间写一篇新的
- vuex之Mutation(三)
说明 既然我们可以取出数据,就可以修改数据,而修改数据并不是像修改data的数据一样,直接 this.xxx = xxx,这样有一个问题,在实际开发中,state的数据一般会多个组件共享,如果可以使用 ...
- MOTS:多目标跟踪和分割论文翻译
MOTS:多目标跟踪和分割论文翻译 摘要: 本文将目前流行的多目标跟踪技术扩展到多目标跟踪与分割技术(MOTS).为了实现这个目标,我们使用半自动化的标注为两个现有的跟踪数据集创建了密集的像素级标注. ...
- mysql常用语句及实题训练
基本语句操作 创建数据库: create database database-name 1 删除数据库: drop database database-name 1 修改数据名: RENAME DAT ...
- Windows下SVN权限配置
Windows下SVN权限配置 按照前面的教程装完1.6.1版以后,当svnadmin create D;\svn创建仓库后,应该在仓库目录下的config目录有3个文件— auth ...
- LeetCode 218. The Skyline Problem 天际线问题(C++/Java)
题目: A city's skyline is the outer contour of the silhouette formed by all the buildings in that city ...
- Codeforces 922 E Birds (背包dp)被define坑了的一题
网页链接:点击打开链接 Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp ne ...
- java2变量数据类型和运算符
public class jh_11_加加减减运算符 { public static void main(String[] args) { int a = 5,b =2 ; a ++;// 对自身 ...