异步处理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 ———————————————————————————————————————— ...
随机推荐
- Shell环境变量文件
/etc/profile 系统级的初始化环境变量文件,由登录Shell调用执行 /etc/profile.d 当/etc/profile运行时,会调用该目录下的一些脚本 /etc/bashrc 每个交 ...
- Struts2与OGNL的联系
1.Struts与OGNL的结合原理 (1)值栈: OGNL表达式要想运行就要准备一个OGNLContext对象,Struts2内部含有一个OGNLContext对象,名字叫做值栈. 值栈也由两部分组 ...
- 整合dubbo的依赖
<!-- 版本信息 --> <properties> <dubbo.version>2.7.3</dubbo.version> <maven-ja ...
- 通过欧拉计划学Rust编程(第54题)
由于研究Libra等数字货币编程技术的需要,学习了一段时间的Rust编程,一不小心刷题上瘾. 刷完欧拉计划中的63道基础题,能学会Rust编程吗? "欧拉计划"的网址: https ...
- (三)(2)wait/notify实现生产者-消费者模型,join方法
生产者,消费者模型 举个例子来说明,厨师,服务员,厨师做菜,服务员上菜,如果厨师没有做好菜,那么服务员就无法上菜,厨师做好了菜,然后通知服务员消费(上菜).在这个过程之中,厨师扮演的就是生产者,服务员 ...
- 一、Mongodb安装和配置
简介 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之间的产品. Mongod ...
- MySQL8.0关系数据库基础教程(三)-select语句详解
1 查询指定字段 在 employee 表找出所有员工的姓名.性别和电子邮箱. SELECT 表示查询,随后列出需要返回的字段,字段间逗号分隔 FROM 表示要从哪个表中进行查询 分号为语句结束符 这 ...
- Java程序员都需要懂的「反射」
前言 只有光头才能变强. 文本已收录至我的GitHub精选文章,欢迎Star:https://github.com/ZhongFuCheng3y/3y 今天来简单写一下Java的反射.本来没打算写反射 ...
- UnityTips:不要在发布版本中实现OnGUI方法
0x00 问题 不知道大家是否在调试Unity应用性能的时候发现过一条常见的Marker:UIEvents.IMGUIRenderOverlays. 很多情况下,这条叫做UIEvents.IMGUIR ...
- Cacti被监控机器 配置 snmp协议
SNMP(Simple Network Management Protocol,简单网络管理协议)的前身是简单网关监控协议(SGMP),用来对通信线路进行管理. snmpd.conf的 ...