异步处理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 ———————————————————————————————————————— ...
随机推荐
- 解题笔记——NIT 遥远的村庄
某个小镇有 N 个村庄,村庄编号1-N,给出 M 条单向道路,不存在环,即不存在 村庄A可以到达村庄B 且 村庄B也可以到达村庄A的情况.如果村庄A与村庄B之间存在一条单向道路,则说村庄A和村庄B之间 ...
- Linux驱动管理
一.驱动更新 本示例为更新网卡驱动,把新的驱动文件放到/root/目录下,然后执行下面的命令 备份已有的文件,将新的文件复制的相应位置 mv /lib/modules/`uname -r`/kerne ...
- VirtualBox 安装ghost版windows XP
昨天尝试在VirtualBox中安装深度技术的GhostXP SP3 V8.02版本的系统,可是安装过程中出现了问题,无法安装,错误提示如下图: 昨天搞了一会,没有结果,今天对于这个无法安装的问题耿耿 ...
- https搭建(自签名证书)
博客搬家: https搭建(自签名证书) 上一篇博客探究了https(ssl)的原理,为了贯彻理论落实于实践的宗旨,本文将记录我搭建https的实操流程,使用Apache2+ubuntu+openss ...
- WeChall_ Training: Stegano I (Training, Stegano)
This is the most basic image stegano I can think of. 解题: 一张小图片,文本方式打开.
- SpringBoot使用ELK日志收集ELASTIC (ELK) STACK
1:资源 # 文档向导 # logstash https://www.elastic.co/guide/en/logstash/current/index.html #kibana https://w ...
- 全网最详细的Linux命令系列-Screen远程会话命令
screen 管理你的远程会话 你是不是经常需要 SSH 或者 telent 远程登录到 Linux 服务器?你是不是经常为一些长时间运行的任务而头疼,比如系统备份.ftp 传输等等.通常情况下我们都 ...
- Speech Super Resolution Generative Adversarial Network
博客作者:凌逆战 博客地址:https://www.cnblogs.com/LXP-Never/p/10874993.html 论文作者:Sefik Emre Eskimez , Kazuhito K ...
- NR / 5G - F-OFDM
- JMeter接口测试-接口签名校验
前言 很多HTTP接口在传参时,需要先对接口的参数进行数据签名加密 如pinter项目的中的签名接口 http://localhost:8080/pinter/com/userInfo 参数为: {& ...