欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決springboot 多線程使用MultipartFile讀取excel文件內(nèi)容報(bào)錯(cuò)問題

 更新時(shí)間:2020年09月27日 09:04:18   作者:csdn565973850  
這篇文章主要介紹了解決springboot 多線程使用MultipartFile讀取excel文件內(nèi)容報(bào)錯(cuò)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

springboot項(xiàng)目開啟多線程

啟動(dòng)類加注解開啟 @EnableAsync,實(shí)現(xiàn)類方法加注解 @Async

前端頁(yè)面

報(bào)錯(cuò)信息

java.io.FileNotFoundException: C:\Users\dongao\AppData\Local\Temp\tomcat.1255209411477782290.8051\work\Tomcat\localhost\ROOT\upload_7d7b99e5_38da_4a03_93e0_bff20cb48022_00000000.tmp (系統(tǒng)找不到指定的文件。)
 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.getInputStream(StandardMultipartHttpServletRequest.java:250)
 at com.dongao.project.utils.UploadUtil.readExcel(UploadUtil.java:156)
 at com.dongao.project.utils.UploadUtil.readExcelToMap(UploadUtil.java:98)
 at com.dongao.project.importbatch.service.ImportBatchServiceImpl.importData(ImportBatchServiceImpl.java:161)
 at com.dongao.project.importbatch.service.ImportBatchServiceImpl$$FastClassBySpringCGLIB$$440ed2f6.invoke(<generated>)
 at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
 at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
 at com.dongao.support.cat.CatUtils.proceed(CatUtils.java:18)
 at com.dongao.support.cat.CatSpringAop.getObject(CatSpringAop.java:26)
 at com.dongao.support.cat.CatSpringAop.aroundServiceMethod(CatSpringAop.java:22)
 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 org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
 at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
 at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
 at com.dongao.project.importbatch.service.ImportBatchServiceImpl$$EnhancerBySpringCGLIB$$a16c4d4e.importData(<generated>)
 at com.dongao.project.importbatch.service.ImportBatchServiceImpl$$FastClassBySpringCGLIB$$440ed2f6.invoke(<generated>)
 at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 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)
:36:46.137 25472 [threadPoolTaskExecutor-1] INFO com.ruoyi.framework.datasource.DynamicDataSourceContextHolder - [setDataSourceType,26] - 切換到SLAVE數(shù)據(jù)源
:36:46.163 25472 [threadPoolTaskExecutor-1] ERROR org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler - [handleUncaughtException,39] - Unexpected exception occurred invoking async method: public void com.dongao.project.importbatch.service.ImportBatchServiceImpl.importData(org.springframework.web.multipart.MultipartFile,java.lang.Long) throws java.lang.Exception
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
 at java.util.ArrayList.rangeCheck(ArrayList.java:653)
 at java.util.ArrayList.get(ArrayList.java:429)
 at com.dongao.project.importbatch.service.ImportBatchServiceImpl.importData(ImportBatchServiceImpl.java:178)
 at com.dongao.project.importbatch.service.ImportBatchServiceImpl$$FastClassBySpringCGLIB$$440ed2f6.invoke(<generated>)
 at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
 at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
 at com.dongao.support.cat.CatUtils.proceed(CatUtils.java:18)
 at com.dongao.support.cat.CatSpringAop.getObject(CatSpringAop.java:26)
 at com.dongao.support.cat.CatSpringAop.aroundServiceMethod(CatSpringAop.java:22)
 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 org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
 at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
 at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
 at com.dongao.project.importbatch.service.ImportBatchServiceImpl$$EnhancerBySpringCGLIB$$a16c4d4e.importData(<generated>)
 at com.dongao.project.importbatch.service.ImportBatchServiceImpl$$FastClassBySpringCGLIB$$440ed2f6.invoke(<generated>)
 at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 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)

問題分析

前端頁(yè)面?zhèn)鬟^來的文件會(huì)存在臨時(shí)文件夾中,如下

C:\Users\dongao\AppData\Local\Temp\tomcat.1255209411477782290.8051\work\Tomcat\localhost\ROOT\

這個(gè)時(shí)候如果單線程操作,即正常程序流程解析是不會(huì)有問題的;

如果走異步多線程解析文件,主線程已經(jīng)結(jié)束了,臨時(shí)文件會(huì)被清空,這時(shí)候再來讀取文件就會(huì)報(bào)錯(cuò)

java.io.FileNotFoundException: C:\Users\dongao\AppData\Local\Temp\tomcat.1255209411477782290.8051\work\Tomcat\localhost\ROOT\upload_7d7b99e5_38da_4a03_93e0_bff20cb48022_00000000.tmp (系統(tǒng)找不到指定的文件。)

問題處理

由于主線程結(jié)束,臨時(shí)文件被清空,導(dǎo)致多線程業(yè)務(wù)類無法獲取到臨時(shí)文件而報(bào)錯(cuò)(系統(tǒng)找不到指定的文件。),此時(shí)可以在主線程中轉(zhuǎn)換獲取文件流信息

InputStream is = file.getInputStream();

文件流信息存儲(chǔ)在內(nèi)存中,多線程時(shí)也可以獲取到文件內(nèi)容,解決問題。

以上這篇解決springboot 多線程使用MultipartFile讀取excel文件內(nèi)容報(bào)錯(cuò)問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Spring Boot Profiles 配置和使用

    詳解Spring Boot Profiles 配置和使用

    本篇文章主要介紹了詳解Spring Boot Profiles 配置和使用,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-06-06
  • Java Metrics系統(tǒng)性能監(jiān)控工具的使用詳解

    Java Metrics系統(tǒng)性能監(jiān)控工具的使用詳解

    Metrics是一個(gè)Java庫(kù),可以對(duì)系統(tǒng)進(jìn)行監(jiān)控,統(tǒng)計(jì)一些系統(tǒng)的性能指標(biāo)。本文就來和大家詳細(xì)聊聊這個(gè)工具的具體使用,希望對(duì)大家有所幫助
    2022-11-11
  • SpringCloud中的Hystrix保護(hù)機(jī)制詳解

    SpringCloud中的Hystrix保護(hù)機(jī)制詳解

    這篇文章主要介紹了SpringCloud中的Hystrix保護(hù)機(jī)制詳解,Hystrix,英文意思是豪豬,全身是刺,看起來就不好惹,是一種保護(hù)機(jī)制,Hystrix也是Netflix公司的一款組件,需要的朋友可以參考下
    2023-12-12
  • 利用Java如何獲取IP與機(jī)器名方法示例

    利用Java如何獲取IP與機(jī)器名方法示例

    在開發(fā)工作中,我們常常需要獲取客戶端的IP。下面這篇文章主要給大家介紹了關(guān)于利用Java如何獲取IP與機(jī)器名的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
    2017-07-07
  • Java逃逸分析詳解及代碼示例

    Java逃逸分析詳解及代碼示例

    這篇文章主要介紹了Java逃逸分析詳解及代碼示例,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-11-11
  • 如何通過idea給web項(xiàng)目打war包

    如何通過idea給web項(xiàng)目打war包

    這篇文章主要介紹了如何通過idea給web項(xiàng)目打war包問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • 關(guān)于IDEA 2020.3 多窗口視圖丟失的問題

    關(guān)于IDEA 2020.3 多窗口視圖丟失的問題

    這篇文章主要介紹了關(guān)于IDEA 2020.3 多窗口視圖丟失的問題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • Java字符串 正則表達(dá)式詳解

    Java字符串 正則表達(dá)式詳解

    這篇文章主要介紹了java使用正則表達(dá)式查找包含的字符串功能,結(jié)合具體實(shí)例形式分析了java針對(duì)字符串匹配查找的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2021-09-09
  • JAVA Frame 窗體背景圖片,首位相接滾動(dòng)代碼實(shí)例

    JAVA Frame 窗體背景圖片,首位相接滾動(dòng)代碼實(shí)例

    這篇文章主要介紹了JAVA Frame 窗體背景圖片,首位相接滾動(dòng)代碼示例,需要的朋友可以參考下復(fù)制代碼
    2017-04-04
  • Java 實(shí)現(xiàn)二叉搜索樹的查找、插入、刪除、遍歷

    Java 實(shí)現(xiàn)二叉搜索樹的查找、插入、刪除、遍歷

    本文主要介紹了Java實(shí)現(xiàn)二叉搜索樹的查找、插入、刪除、遍歷等內(nèi)容。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02

最新評(píng)論