when you are using tomcat as you application server for not small application you can easy get (out of memory exception). this is because the default heap size tomcat use is small and suitable only for small web applications.
to set the start and maximum heap size run the following command before starting your tomcat:
export CATALINA_OPTS=”-Xms256m -Xmx512m”
or
export JAVA_OPTS=”-Xms256m -Xmx512m”
this will create environment variable called CATALINA_OPTS or JAVA_OPTS contains the required options to make tomcat start heap size 256M and maximum heap size 512M.
I am new for Tomcat6 and I am trying to increase my heap size. I have the Windows NT.
But I do not know how to run this command stated above? From where ?
I also looked for the Catalina.sh or Catalina.bat files ın the Tomcat ınstall directory ın order to change the environment varıable manually, but these fıles do not exist. Can you plese help me ?
Dear Fatih,
to set the memory heap size in windows you have to create environment variable with name CATALINA_OPTS and value -Xms256m -Xmx512m of course you can change the 256 and the 512 to whatever values you want.
regarding the catalina.sh or catalina.bat you can find them on the bin directory in your tomcat cat folder.
if u have any other problems regarding this issue i’ll be glad to hear from you.
I am using Tomcat as a web application server, on Linux and I have the following in my startup.sh for configuring the heap-size.
Is this wrong? I had found this on some web page but can’t locate that page now. I am wondering if the out of memory errors that I am getting is because the settings below are wrong.. If it is right, must I have the DXms setting too? If the settings below are OK, what does the D in the parameter denote?
JAVA_OPT=”-DXmn1536m -DXmx2560m”; export JAVA_OPT
Joe
Hello Joe,
the catalina start up script looks for environment variable JAVA_OPTS but you are using JAVA_OPT without the S at the end.
I have Windows XP and how can I set the memory heap size ?
Do you know the correct command to change heap size ?
I tried to use the following command but it did not work :
set JAVA_OPTS=”-Xms256m -Xmx512m”
please give answer
Dear Fatih,
for setting the JAVA_OPTS variable in windows you don’t need to type a command. all you need is to set the environment variable as following:
– right click on my computer icon and click select properties.
– select the advanced tab.
– click on environment variables button.
– on system variables part :
– click on new button.
– in the variable name type : JAVA_OPTS
– in the variable value type: -Xms256m -Xmx512m
– click ok and ok.
now you have the environment variable JAVA_OPTS set to -Xms256m -Xmx512m.
Hi Mostafa,
I’m very new to this setting JAVA_OPTS variable.
Please can you explain in detail.
Stepwise proc (as explained for window) for configuring
for linux machines as well(not much aware about the linux commands aswell)
–one more question :
1) If i have two tomcat application running on my windows XP ,does this JAVA_OPTS
size apply for both, if yes how to make it specific for each application.
2)what does Xms and DXms stand for.
Thanks in advance
Thanks Mostafa but I already know that way
But I need the correct cmd for my batch file
what batch file you mean here?
After installation of my program on my customer’s computer a batch file automatically runs at the end of the installation.
This batch file contains necessary commands to set the necessary parameters for my program.
And I should also add the “setting JAVA_OPTS environment variable” command to this batch file to make my program working better.
Because my program uses tomcat as the application server, I need to increase heap size automatically after the installation.
Fatih,
i think this command can help you in this case : http://www.ss64.com/nt/setx.html
but i really recommend you to use linux on your customer platform instead of windows.
Hi all,
I am new with Tomcat….
I have a question that I am facing every day.
I need to increase the tomcat memory Xms and Xmx … OS is windows .
Server Ram is 8G … I need to increase Xms to 1536m and Xmx to 4000m . because users need to view more than 18000 thumbnails in the page… and he system keeps giving me OutOfMemory Error … Plz … I need your help
Dear Feras,
please read this thread from the beginning and you will find how to set the heap size for tomcat just replace the amount i used with the amounts you need.
also displaying 18000 thumbnails in one page is not a good idea at all you can use paging to minimize the amount of thumbnails you display in a single page.
i wish i helped you
and wait your comments.
Hello,
I am getting OutofMemory error everyday and I need to restart the tomcat and thereafter it works fine. I have already set the JAVA_OPTS environment variable in WINDOWS System Variable specifying the maximum heap size of 1024.
But this option didnot work out and still the problem persist.
Can you please help me out from this problem.
Thanks,
Sandeep
Hello Sandeep,
try to set both xmx and xms.
if it didn’t work, so u need to review your application because there is something wrong there. such as creating and loading recursive objects or so. if u like i may help u in that.
Regards
Mostafa
Hi Mostafa,
These are the options i tried
1) setting -Xms1024m -Xmx1024m -XX:MaxPermSize=128m as JAVA_OPTS. Should i try this same setting in catalina.bat file instead as system environment variable?
2) Introspector.flushCaches(); in the destroy() method of servelet.
Second option worked for a day. Server didn’t go down.But very next day it did. The weird thing is, site don’t go down on weekends. Let’s see for today as today is a Saturday.
What we have observed is, when the site is about to go down, java.exe usage remains high and after the tomcat restart it goes down. Does this say anything?
Thanks for your reply,
Sandeep
dear Sandeep,
remove the -xx from the java_opts just use -Xms1024m -Xmx1024m
second the reason for not being down in weekends this is normal as usually server hits is much less than normal in weekends.
we can communicate by email if u want more support. please send me your email.
Regards
Mostafa
Hi Mostafa,
I will try the option by removing XX.
Thanks,
Sandeep
Hi Mostafa
So now my JAVA_OPTS option looks like this
-Xms1024m -Xmx1024m :MaxPermSize=128m
I made a change now. Also i wrote an email address in the Mail field.
Thanks,
Sandeep
Hi Mostafa,
Making a JAVA_OPTS change in system environment variable didn’t work out. Does it make any difference if i make the same change in catalina.bat file?
Or can you suggest me some other option?
Awaiting for your reply,
Thanks,
Sandeep
Hello Sandeep,
first you need to be sure if the xmx and xms options really executed or not to do so.
in your application insert the following code:
System.out.prinln(“max memory: ” + Runtime.getRuntime().maxMemory() / (1024*1024));
System.out.prinln(“available memory: “+Runtime.getRuntime().freeMemory() / (1024*1024));
System.out.prinln(“total memory : “+ Runtime.getRuntime().totalMemory() / (1024*1024));
this will print on the console the needed information.
Regards
Mostafa
Hi Mostafa,
The output is coming is out be 128,1,1 for the above 3 sysouts.
Thanks,
Sandeep
Hi Sandeep,
from the the output i see that the xms and xmx didn’t apply for your tomcat.
try to add
SETX JAVA_OPTS=”-Xms256m -Xmx512m”
in your catalina.bat
and reply me with the output after that.
Regards
Hi Mostafa,
Please ignore the above output. Sorry about that. I mistakenly tested with other tomcat.
Current situation:JAVA_OPTS environment variable is:-Xms512m -Xmx1024m
And the latest values are coming out to be:832,21,338 for the above mentioned sysout.
Thanks,
Sandeep
Hi Sandeep,
so the problem isn’t setting the heap size for the tomcat, it may be bad resource management in the application it self.
here is my email address if u want support: mostafa_hashem@hotmail.com
Regards
Mostafa
Hi Mostafa,
Thanks for your support. I will contact you soon.
Thanks,
Sandeep
Hi,
Mostafa
I am going with the same problem that sandeep having.I gone through your discussion.but still not able to solve the heap problem.
I have linux server with apache tomcat 5.5.25 install and the jdk is jdk1.6.0
Already done with setting CATALINA _OPTS and JAVA_OPTS in catalina.bat. I tested by the code
System.out.prinln(”max memory: ” + Runtime.getRuntime().maxMemory() / (1024*1024));
System.out.prinln(”available memory: “+Runtime.getRuntime().freeMemory() / (1024*1024));
System.out.prinln(”total memory : “+ Runtime.getRuntime().totalMemory() / (1024*1024));
still i m getting out put as 63 4 4
can you please refer to this?I am in big trouble please help me out of this.
Regards
Tushar
Hi mostafa
THanks for your reply ,I am giving “-Xms786m -Xmx786m” for CATALINA_OPTS as well as JAVA_OPTS if I go with command like
java -Xms786m -Xmx786m helloworld it works but i can’t go with that way as i have to set the heap size for entire webserver where many sites are hosted and each site can have many classes in it
regards
Tushar
;
THanks fantastic
Dear The YPI,
thanks for visiting my blog
Hi Mostafa,
I have WIN2K3 server and using tomcat6 as app server.
the conf or bin folder of tomcat doesn’t have any catalina.bat or there is nothing like JAVA_OPTS is declared any where can you guide me the way to resize the JVM heap other then system verables.
Thanks,Atul
Hi All,
What is the maximum memory that I can allocate to tomcat (i.e. for Xmx)? I am running tomcat in a 64bit linux machine with 16GB RAM and wondering if I can allocate around 3GB for tomcat.
In windows, the easiest way to do it is to install the Tomcat Monitor.
Right click the icon in the Systray
Choose Configure
Click the Java Tab
Set the Initial and Maximum memory pool opttions
Click ok
Restart Tomcat
You can verify taht the settings are correct with a tool such as Lamba Probe
http://www.lambdaprobe.org
Hi Mostafa..
i’m using MacOSX.. and my applicaion is on a remote machine on the tomcat server.. i use JDBC to retrieve data.. when the result set has too many data then the heap size error is shown.. i have tried adding the ‘-export CATALINA_OPTS = -Xms256m -Xmx512m” in the catalina.sh and the startup.sh both the files. and when i start the server it starts but then shows an error saying ‘invalid command ‘export: = ‘
invalid command ‘export: -Xms256m’
invalid command ‘export: -Xms512m’
what do i do??? can i add the statement anywhere in the .sh file or some specific place only??
Thanks…
In my catalina.sh file, I am using the following command:
JAVA_OPTS=”-Xmx1024m -Xms1024m”
I see where others are using “export” before the JAVA_OPTS. So I have two questions:
1. What is the difference between using “export” and not using “export”?
2. Does it matter?
Thanks!
Hi,
i have tried all methods, but my heap size doesn’t go up.
My output is:
max memory: 63
available memory: 22
total memory : 63
I’m using windowXP, and Tomcat 5.5.15
Any help is appreciated.
I solved the problem. In the section paparameters in tun configuration in eclipse you put the Xms Xmx you need.
Hi all,
I suggest you to use Jconsole to monitor tomcat.
You need to set the memory size according to your traffic pattern. If you reserve high memory the gc will rarely and this will allow to tomcat to handle request more easy, but when gc will run it will take much time some you are using a large amount of memory.
Also, use the same value to Xms and Xmx and let the VM to adjust the MaxPermSize according to its needs.
Ramzi
Thank you so much.your article is very useful.My issue got fixed
very nice article..
use this for jsp pages
max memory:
available memory:
total memory :
Helped me while trying to fine tune my application server.
Thanks!
very glad to hear that
On Windows I have always set this through the Apache Monitor ‘configure’ tag under java options.
But I was just wondering how would I set this on a Linux server?
Hey just go to tomcat/bin folder.
you get there catalina.sh file.
You will get the following line:-
JAVA_OPTS=”-d32 -server -Xms64m -Xmx512m
set the size as you like or based on you OS.
Enjoy
Here is a simple way to do it with eclipse
http://viralpatel.net/blogs/2009/10/setting-tomcat-heap-size-jvm-heap-eclipse.html
Thanks dude………..
It Works…..
hi
i have a problem with tomcat 5. we are using webservices to get the data from oracle.Here the front end calling service would be in .net.when i sned the request to java webservices , it takes too much time . i dont know what is the problem .plz let me know if anybody getting an idea…………………………
Hi Mostafa,
I am using Windows server 2008 and using Tomcat 7.0.22.
I am fetching 3 lakhs records in the memory. I have server RAM size is 12 GB and file size is 23 MB. I have followed all the steps like setting environment variable to increase HEAP size but still it is giving me this exception
“http-apr-8080-exec-9” java.lang.OutOfMemoryError: GC overhead limit exceeded.
Please help me out to solve this issue.
Hi Guys will you please help me out to solve the memory issue. as i am not getting proper answer.
Hi Devang,
Follow the answer below.
Note : If needed, you can increase the size from 512 to 1024M but first, test it as defined…
For Windows, in the conf folder of tomcat, create a new file named setenv.bat and put the following into the file:
set JAVA_OPTS=-XX:MaxPermSize=512m -Xms512M -Xmx1024M %JAVA_OPTS%
Hello Mustafa,
we are using a web application to fetch reports. A report may contain more than 1 million records for a date range. I need to show all these records in a flex datagrid. While fetching the records it is throwing “Heap space error: Out of memory error”. I have tried using the JAVA_OPTS -Xms512 -Xmx1024 option in environment variable but no luck. Please help me.
Hello Chandu,
what version of tomcat you are using?
I am using Tomcat 6.20. I have updated JVM heap space memory to -Xms512m -Xmx1280m. Now i am able to fetch 3 Lack records but taking much time to load. In my project using FLEX 3.0, Springs, Hibernate, JPA. The error showing as
[BlazeDS] Java heap space
java.lang.OutOfMemoryError: Java heap space
Thank you for your reply. Please tell me what are all the possible ways to improve performance.
Dear Chandu,
how many records does your application return when you got the memory error?
Hello Mustafa,
No records are retrieved when i get memory error. I have a requirement to fetch 27 Million records in a single search. We have exporting functionality also. We are using jasper reports to generate CSV report.
Please reply, I am waiting for your reply. Please let me know what are all the ways to fix this problem. Weather it is from DB side or any other settings.
Thanks in advance.
Regards,
Chandu
please, send me the exception log
Hello Mustafa,
Please find the exception details below
2012-03-30 18:03:58,697 ERROR [org.springframework.transaction.interceptor.TransactionInterceptor] Application exception overridden by rollback exception
java.lang.OutOfMemoryError: Java heap space
at java.text.RuleBasedBreakIterator.readFile(Unknown Source)
at java.text.RuleBasedBreakIterator.readTables(Unknown Source)
at java.text.RuleBasedBreakIterator.(Unknown Source)
at java.text.BreakIterator.createBreakInstance(Unknown Source)
at java.text.BreakIterator.getBreakInstance(Unknown Source)
at java.text.BreakIterator.getLineInstance(Unknown Source)
at java.text.BreakIterator.getLineInstance(Unknown Source)
at java.awt.font.LineBreakMeasurer.(Unknown Source)
at net.sf.jasperreports.engine.fill.TextMeasurer.renderParagraph(TextMeasurer.java:436)
at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:397)
at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:1130)
at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:540)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:329)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:419)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:378)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2038)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:760)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportContent(JRVerticalFiller.java:290)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:132)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:946)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:864)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:84)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:513)
at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:465)
at com.ncr.billpay.activitymanager.service.impl.ActivityManagerServiceImpl.processReports(ActivityManagerServiceImpl.java:254)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
Salam Mostafa Bhai,
I am using Linux Mint… I am given a task to increase the memory of Tomcat And JAVA using terminal (CDI)….
Kindly tell me how I Could do that? plz give me full code.
Thanks for your kind assistance.
Hi
I am using tomct application server where I am running 3 instances. Now I wish to connect my instances with jconsole. I have set the port no for JMX is 8999. Now i can view this throught jconsole. And after a long try , i was not able to find the way how to set the threshold value for the instances. If any body knows how to set the threshold value for tomct, please let me know..
Thanks,
Dilip .
Great blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple tweeks would really make my blog stand out.
Please let me know where you got your design. Bless you
Wow, wonderful blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your web site is excellent, as well as the content! kdgbdgbkbbeg
Thanks for your personal marvelous posting! I seriously enjoyed reading
it, you happen to be a great author.I will remember to bookmark
your blog and may come back sometime soon. I want to encourage you to definitely continue your great job, have
a nice evening!
I’ve been exploring for a bit for any high quality articles or blog posts on this kind of area . Exploring in Yahoo I eventually stumbled upon this site. Studying this info So i’m happy to exhibit that I’ve an incredibly excellent uncanny feeling I found out exactly what I needed. I most indubitably will make certain to don?t put out of your mind this web site and give it a look on a continuing basis.|