国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:129日期:2022-06-16 18:18:44

springboot項目開啟多線程

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

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

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

前端頁面

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

報錯信息

java.io.FileNotFoundException: C:UsersdongaoAppDataLocalTemptomcat.1255209411477782290.8051workTomcatlocalhostROOTupload_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.Exceptionjava.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)

問題分析

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

C:UsersdongaoAppDataLocalTemptomcat.1255209411477782290.8051workTomcatlocalhostROOT

這個時候如果單線程操作,即正常程序流程解析是不會有問題的;

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

java.io.FileNotFoundException: C:UsersdongaoAppDataLocalTemptomcat.1255209411477782290.8051workTomcatlocalhostROOTupload_7d7b99e5_38da_4a03_93e0_bff20cb48022_00000000.tmp (系統(tǒng)找不到指定的文件。)

問題處理

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

InputStream is = file.getInputStream();

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

以上這篇解決springboot 多線程使用MultipartFile讀取excel文件內(nèi)容報錯問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標簽: excel
相關(guān)文章:
主站蜘蛛池模板: 国产久视频 | 亚洲视频在线观看免费视频 | 亚洲在线日韩 | 99久国产 | 美女张开腿让男人桶爽免费网站 | 国产大乳孕妇喷奶水在线观看 | 12至16末成年毛片视频 | 一区二区网站 | 中文字幕日韩三级 | 亚洲黄色美女视频 | 精品国产亚一区二区三区 | a一级特黄日本大片 s色 | 18videosex性欧美69 | 成人毛片手机版免费看 | 亚洲午夜成激人情在线影院 | 男人的天堂中文字幕 | 99视频在线观看视频一区 | 精品精品国产高清a毛片 | 在线毛片一区二区不卡视频 | 国产精品资源在线 | 久久99精品国产免费观看 | 日本wwwwwwwww| 东莞a级毛片 | 欧美视频在线一区二区三区 | 92精品国产自产在线观看 | 亚洲 欧美 都市 自拍 在线 | 国产成人亚洲综合一区 | 欧美一级片 在线播放 | 国产黄色小视频在线观看 | 成年人视频在线免费看 | 久久免费观看视频 | 91精品日本久久久久久牛牛 | 中文字幕在线播放视频 | 不卡无毒免费毛片视频观看 | 国产精品亚欧美一区二区三区 | 欧美操人视频 | 在线 中文字幕 日韩 欧美 | 在线成人免费视频 | 午夜视频一区二区 | 最新国产精品好看的国产精品 | 欧美成人免费一区在线播放 |