詳解SpringBoot中的tomcat優(yōu)化和修改
項(xiàng)目背景
在做項(xiàng)目的時(shí)候,把SpringBoot的項(xiàng)目打包成安裝包了,在客戶上面安裝運(yùn)行,一切都是那么的完美,可是發(fā)生了意外,對(duì)方突然說導(dǎo)出導(dǎo)入的文件都不行了。我急急忙忙的查看日志,發(fā)現(xiàn)報(bào)了一個(gè)錯(cuò)誤
java.io.IOException: The temporary upload location [C:\Windows\Temp\tomcat.1351070438015228346.8884\work\Tomcat\localhost\ROOT] is not valid at org.apache.catalina.connector.Request.parseParts(Request.java:2821) at org.apache.catalina.connector.Request.parseParameters(Request.java:3185) at org.apache.catalina.connector.Request.getParameter(Request.java:1116) at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:84) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)
經(jīng)過分析發(fā)現(xiàn),這是tomcat在啟動(dòng)的時(shí)候會(huì)生成一個(gè)臨時(shí)的上傳文件保存的位置,但是這個(gè)位子默認(rèn)是放在系統(tǒng)的臨時(shí)文件夾中。當(dāng)這個(gè)tomcat創(chuàng)建的文件夾被系統(tǒng)刪除后,這時(shí)在上傳文件就出現(xiàn)問題了??赡軐?duì)方服務(wù)器裝上了360管家,會(huì)自動(dòng)刪掉好似
開工
針對(duì)這一個(gè)異常有以下解決方法
1.萬能的重啟,絕大多數(shù)的問題解決方法,“你重啟一下試試”。但是這個(gè)方法只能解決得了一時(shí),解決不了一世啊。
2.在配置文件中加上
server.tomcat.basedir=自定義目錄
3.啟動(dòng)jar包的時(shí)候加上參數(shù) -Djava.io.tmpdir=自定義目錄
java -jar xx.jar -Djava.io.tmpdir=自定義目錄
4.添加配置bean
import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.servlet.MultipartConfigElement; @Configuration public class TomcatBeanConfig { /** * 文件上傳臨時(shí)路徑 */ @Bean MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setLocation("自定義目錄"); return factory.createMultipartConfig(); } }
-------------------------------------分隔符 ------------------------------------------
接著說優(yōu)化,至于優(yōu)化,我在解決上面的問題發(fā)現(xiàn),tomcat中有一個(gè)配置
# 后臺(tái)線程方法的delay大小每隔900s清除過期的session會(huì)話 server.tomcat.background-processor-delay=900
默認(rèn)值是10, 每隔10s發(fā)生一次young gc,并且CPU使用率長(zhǎng)期大于10%。
ContainerBackgroundProcessor這個(gè)線程是干什么的?
Tomcat的Engine會(huì)啟動(dòng)一個(gè)線程(就是ContainerBackgroundProcessor),該線程每10s會(huì)發(fā)送一個(gè)發(fā)送一個(gè)事件,監(jiān)聽到該事件的部署配置類會(huì)自動(dòng)去掃描webapp文件夾下的war包,將其加載成一個(gè)Context,即啟動(dòng)一個(gè)web服務(wù)。同時(shí),該線程還會(huì)調(diào)用子容器Engine、Host、Context、Wrapper各容器組件及與它們相關(guān)的其它組件的backgroundProcess方法。
個(gè)人理解是,每隔10S對(duì)session的過期清理過于頻繁從而導(dǎo)致CPU占用率過高,
我改成了900,就是每900秒檢測(cè)一次,這樣就降低CPU占用率啦
backgroundProcess對(duì)spring mvc的影響 主要影響session的過期清理,如果設(shè)置為900, 就只會(huì)每隔900s清除過期的session會(huì)話。 server.tomcat.background-processor-delay = 900s #調(diào)用backgroundProcess方法之間的延遲。如果未指定持續(xù)時(shí)間后綴,則將使用秒。
到此這篇關(guān)于詳解SpringBoot中的tomcat優(yōu)化和修改的文章就介紹到這了,更多相關(guān)SpringBoot tomcat優(yōu)化和修改內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
checkpoint 機(jī)制具體實(shí)現(xiàn)示例詳解
這篇文章主要為大家介紹了checkpoint 機(jī)制具體實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02Maven安裝本地的jar包和創(chuàng)建帶模板的自定義項(xiàng)目的操作過程
這篇文章主要介紹了Maven安裝本地的jar包和創(chuàng)建帶模板的自定義項(xiàng)目,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-03-03java枚舉enum,根據(jù)value值獲取key鍵的操作
這篇文章主要介紹了java枚舉enum,根據(jù)value值獲取key鍵的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-02-02Spring @Scheduler使用cron表達(dá)式時(shí)的執(zhí)行問題詳解
Spring給程序猿們帶來了許多便利。下面這篇文章主要給大家介紹了關(guān)于Spring @Scheduler使用cron表達(dá)式時(shí)的執(zhí)行問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09Spring啟動(dòng)流程refresh()源碼深入解析
這篇文章主要給大家介紹了關(guān)于Spring啟動(dòng)流程refresh()源碼深入解析的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09SpringBoot @PropertySource與@ImportResource有什么區(qū)別
這篇文章主要介紹了SpringBoot @PropertySource與@ImportResource有什么區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-01-01Java實(shí)現(xiàn)滑動(dòng)驗(yàn)證碼生成(后端工具類)
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)滑動(dòng)驗(yàn)證碼生成功能中的后端工具類部分,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-10-10Java虛擬機(jī)調(diào)用Java主類的main()方法
這篇文章主要介紹了Java虛擬機(jī)調(diào)用Java主類的main()方法,前一篇文章我們介紹了關(guān)于Java虛擬機(jī)HotSpot2021-11-11