问题
In my Spring Boot application I want to upload files into a MySql database. When I want to upload large files, I get java.lang.OutOfMemoryError: Java heap space
exception. I get it with files about over 60Mb which seems normal because as I know 64Mb is the default heap size.
I've run Tomcat8w.exe and on the Java tab I've added the following lines to the Java Options:
-Xms512m
-Xmx8192m
-XX:PermSize=512m
-XX:MaxPermSize=1024m
Also, I've created a setenv.bat file into the bin folder with the following content:
JAVA_OPTS="-Xms1024m -Xmx2048m"
Neither of these worked for me. In catalina-log I see these lines when I start Tomcat:
29-Oct-2016 15:39:42.481 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms512m
29-Oct-2016 15:39:42.481 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx8192m
29-Oct-2016 15:39:42.482 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:PermSize=512m
29-Oct-2016 15:39:42.482 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:MaxPermSize=1024m
29-Oct-2016 15:39:42.482 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: exit
29-Oct-2016 15:39:42.482 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms256m
29-Oct-2016 15:39:42.483 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx512m
I have to add that I don't know where the last two lines come from, those are not the values I've specified.
Please, help me, what I do wrong. I need to upload files up to 100Mb.
回答1:
You should change the settings of the windows service in registry if you use the windows service. There is also possible to specify other startup parameters, she shell scripts settings are (at least partially) ignored in some files, if you are going to start the Tomcat as windows service.
Go and navigate to the reqistry with the key name (or similar name in the case of the other windows than in my case Windows Server 2012 R2 64 bit):
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\{tomcat-service-name}\Parameters\Java
(replace {tomcat-service-name} by your specific value) and you should see the parameters like JvmMx, JvmMs, Classpath, Options, which can be used to tweak the started jvm. I would guess, the values 256 and 512 are specified as JvmMs and JvmMx, change them to your desired value.
来源:https://stackoverflow.com/questions/40319709/tomcat-java-lang-outofmemoryerror-java-heap-space