Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase heap size for jBoss server

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.

like image 330
youraj Avatar asked Jun 06 '11 13:06

youraj


People also ask

How can I increase my Wildfly memory?

We can simply open it and update the -Xmx option in the following line (change the number as per the requirement): JAVA_OPTS="-Xms64m -Xmx512m ..." This will set the heap memory while starting up the server.

How much heap size we can increase?

You can increase to 2GB on a 32 bit system. If you're on a 64 bit system you can go higher.


3 Answers

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.

like image 130
BalusC Avatar answered Oct 05 '22 14:10

BalusC


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

like image 32
Camilo Avatar answered Oct 05 '22 14:10

Camilo


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
like image 6
kmaqsudi Avatar answered Oct 05 '22 13:10

kmaqsudi