How to increase heap size for jBoss server

2019-02-06 15:07发布

I have an upload files scenario in my project. When I'm trying to upload the large files it's giving me an OutOfMemory error. That error is related to Java heap size.

How can you increase the heap size in Java and which file do I need to alter for this? I'm using jboss 5.1 server for running my application.

8条回答
beautiful°
2楼-- · 2019-02-06 15:43

On wildfly 8 and later, go to /bin/standalone.conf and put your JAVA_OPTS there, with all you need.

查看更多
爷、活的狠高调
3楼-- · 2019-02-06 15:45

Look in your JBoss bin folder for the file run.bat (run.sh on Unix)

look for the line set JAVA_OPTS, (or just JAVA_OPTS on Unix) at the end of that line add -Xmx512m. Change the number to the amount of memory you want to allocate to JBoss.

If you are using a custom script to start your jboss instance, you can add the set JAVA_OPTS option there as well.

查看更多
戒情不戒烟
4楼-- · 2019-02-06 15:46

Use -Xms and -Xmx command line options when runing java:

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size

For more help type java -X in command line.

查看更多
The star\"
5楼-- · 2019-02-06 15:47

You can set it as JVM arguments the usual way, e.g. -Xms1024m -Xmx2048m for a minimum heap of 1GB and maximum heap of 2GB. JBoss will use the JAVA_OPTS environment variable to include additional JVM arguments, you could specify it in the /bin/run.conf.bat file:

set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m"

However, this is more a workaround than a real solution. If multiple users concurrently uploads big files, you'll hit the same problem sooner or later. You would need to keep increasing memory for nothing. You should rather configure your file upload parser to store the uploaded file on temp disk instead of entirely in memory. As long as it's unclear which parser you're using, no suitable answer can be given. However, more than often Apache Commons FileUpload is used under the covers, you should then read the documentation with "threshold size" as keyword to configure the memory limit for uploaded files. When the file size is beyond the threshold, it would then be written to disk.

查看更多
一纸荒年 Trace。
6楼-- · 2019-02-06 15:51

What to change?

set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m"

Where to change? (Normally)

bin/standalone.conf(Linux) standalone.conf.bat(Windows)

What if you are using custom script which overrides the existing settings? then?

setJBosssEnvironment.cmd/.sh (kind of file name will be there)

More information are already provided by some of our committee members! BalusC.

查看更多
Viruses.
7楼-- · 2019-02-06 16:00

Edit the following entry in the run.conf file. But if you have multiple JVMs running on the same JBoss, you might want to run it via command line argument of -Xms2g -Xmx4g (or whatever your preferred start/max memory settings are.

if [ "x$JAVA_OPTS" = "x" ]; then
    JAVA_OPTS="-Xms2g -Xmx4g -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true
查看更多
登录 后发表回答