BACKGROUND: I have a web Project which uses JSP. The IDE is Eclipse.
The configuration of tomcat is: Automatically publish when resources change and publishing interval is "1 second".
A property file in the classes folder which used to save some settings.It also can be dynamically modified by the servlet. The modify operation is trigerred by the save button in the JSP.
PROBLEM: After several save operation, Tomcat come with java.lang.OutOfMemoryError: PermGen space.
LOG MESSAGE
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1815)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:108)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:58)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1064)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4238)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3083)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:404)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1279)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1580)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1580)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1560)
at java.lang.Thread.run(Thread.java:662)
Tomcat does need a lot of permgen. 512m is not an unreasonable max. However it only delays the hot-deploy leak. Permgen will grow ~25mb per hotdeploy, which, in Eclipse, might be every time you save a Java file. 512m disappears fast if you have a Ctrl+S twitch like me.
The solution: allow Java to kick class definitions out of memory, i.e., garbage collect byte code. Add these along with your boosted permgen size:
-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC
You may set environment variable named : "JAVA_OPTS" and set value of it as follows -Xms256m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m
FOR ECLIPSE
Go to server properties
Go to platform
Now in VM argument write this
-Xms256m -Xmx256m -XX:PermSize=256m -XX:MaxPermSize=512m
FOR NETBEANS
Go to Netbeans folder/etc/
open netbeans.config in any editor
edit this line as
netbeans_default_options="-J-client -J-Xss256m -J-Xms256m -J-XX:PermSize=256m -XX:MaxPermSize=512m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true"
Thats all
setting like this:
-Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m
Just configure it from the apache tomcat interface:
start C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\Tomcat8w.exe (or you may just search in windows start for "Configure Tomcat");
Go to Java tab;
Set the required space in the input fields:
Just to add for Windows, if someone is still stuck:--
Open catalina.bat file (located at Apache tomcat installation folder/bin)
Set JAVA_OPTS as follows in the very start(before actually its first use anywhere in the file):--
set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m
Restart Tomcat and its done.
You can find nice explanation here
Tomcat server runs different JAVA and the eclipse runs in different JAVA.
So adding -XX:MaxPermSize=512m to eclipse.ini will help resolving this issue. Follow the below steps to add this to tomcat server:
Double click server in eclipse
open launch configuration
add "-XX:MaxPermSize=512m" to VM arguments in the Arguments tab.
Related
I've deployed an application in tomcat 7.0.55 for testing.I want to capture whether "HeapDumpOnOutOfMemoryError" is occurring or not . Following are my JVM parameters.
JAVA_OPTS="-server -Xms512M -Xmx2048M -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ThreadStackSize=512 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/apps/dumps/"
I don't see any file under the directory. Does it create a file under the directory or i've to manually create a file to append ?
You can use it as below :
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=
You can also manually generate a memory map using jmap if you know the process id:
jmap -J-d64 -dump:format=b,file=
You can use JHat to analyze the dump.
jhat "path to dump file".
By default the heap dump is created in a file called java_pid.hprof in the working directory of the VM, as in the example above. You can specify an alternative file name or directory with the -XX:HeapDumpPath= option. For example -XX:HeapDumpPath=/disk2/dumps will cause the heap dump to be generated in the /disk2/dumps directory.
Check if it is a permissions issue to write to the configured folder /apps/dumps/.
For reference -
https://blog.gceasy.io/2015/08/14/how-to-capture-heap-dump-jmap/
https://blogs.oracle.com/LuzMestre/entry/how_to_collect_a_heap
I am getting this error in tomcat server.
Exception in thread "http-bio-8080-exec-17"
Exception in thread "http-bio-8080-exec-2"
Exception in thread "http-bio-8080-exec-15"
Exception in thread "http-bio-8080-exec-20"
Exception in thread "http-bio-8080-exec-18"
java.lang.OutOfMemoryError: Java heap space.
I have seen MAT but how do I generate the .hprof file in my Tomcat server.
Thank you.
to remove the error edit the file
/etc/default/tomcat7
replace with:
JAVA_OPTS="-Djava.awt.headless=true -Xmx1280m -XX:+UseConcMarkSweepGC"
Then restart the web server.
Xmx is the new maximum size of memory and it should be affordable by your machine.
add this line to /path/to/tomcat/bin/setenv.sh (if doesn't exist create it) :
CATALINA_OPTS="$CATALINA_OPTS -server -Xms256m -Xmx1024m"
this increases tomcat's heap size to 1024MB.
Solution as per your OS:
if Ubuntu:
open .bashrc file available in user home folder (it is hidden) and Add or Edit one line among last 2-3 lines:
export CATALINA_OPTS="-Xms512m -Xmx1024m"
else Windows:
In your environment variables add/edit
CATALINA_OPTS = "-Xms512m -Xmx1024m"
Go to /bin and create a file named setenv.sh for Linux systems or setenv.bat for Windows.
Inside the setenv file, use the following format to set the heap size using the following parameters:
-Linux:
export CATALINA_OPTS="-Xms4096M -Xmx4096M"
-Windows:
set CATALINA_OPTS=-Xms4096M -Xmx4096M
Make sure both the values match for minimum and maximum.
Save the file and restart Tomcat.
How do I increase the memory used by my Weblogic (Java). While starting the server from eclipse it shows a message that JAVA Memory arguments: -Xms256m -Xmx512m -XX:MaxPermSize=256m. I couldn't understand from where is it taking that value from. After sometime the Weblogic server fails because of low permgen space.
I added startup arguments from console but that doesn't have any effect. Can you help me from where is it taking the memory values from?
When you configure a "Server" in Eclipse for WebLogic, you select a domain directory (for local). That domain directory contains the startup scripts that Eclipse will use to start the WebLogic Server. These are the same scripts that you would use if you started the server if you did it without Eclipse. Inside the domain directory is a folder called "bin". In the "bin" directory, locate the setDomainEnv file (.sh for unix, or .cmd for Windows). In that file, alter the memory settings to suite your needs.
Based on the error message you mentioned in your question, I would increase both the PermSize and MaxPermSize settings to 512m. For PermSize and MaxPermSize, there are two locations each by default in a simple WLS installation, one for 32-bit, and another for 64-bit. It won't hurt to change them both. But if you know which JVM architecture you are running, you can change the one that applies to your environment.
You will have a file setDomainEnv.cmd/setDomainEnv.sh under your server bin folder. this file contains
set MEM_MAX_PERM_SIZE_64BIT=-XX:MaxPermSize=512m
set MEM_MAX_PERM_SIZE_32BIT=-XX:MaxPermSize=512m
Max and Min memory values as
if "%JAVA_VENDOR%"=="Sun" (
set WLS_MEM_ARGS_64BIT=-Xms256m -Xmx512m
set WLS_MEM_ARGS_32BIT=-Xms256m -Xmx512m
) else (
set WLS_MEM_ARGS_64BIT=-Xms512m -Xmx512m
set WLS_MEM_ARGS_32BIT=-Xms512m -Xmx512m
)
You can update the values inside it.
In addition to the previous two answers that are correct (modifying setDomainEnv and potentially wl_server\common\bin\commEnv), you can also modify servers individually if you are starting them with the nodemanager.
In the admin console navigate to:
Servers -> <server name> -> Server Start tab -> Arguments
Here you can set the JVM args you want for that server rather than making a blanket change in all servers to setDomainEnv
Looks like eclipse plugin adds it own USER_MEM_ARGS variable, so it should be rewritten using following approach:
Open following file:
$WL_HOME/user_projects/domains/mydomain/bin/setDomainEnv.sh
and add the next line to it (e.g. after help description)
USER_MEM_ARGS=$ECLIPSE_MEM_ARGS
Then, open weblogic server properties (double click at weblogic in servers view) and click "Open launch configuration". In a opened window select "Environment" and add new variable ECLIPSE_MEM_ARGS with memory params as value, e.g.:
ECLIPSE_MEM_ARGS=-Xms1024m -Xmx2048m -XX:MaxPermSize=512m
Save and check that server was applied new configuration.
P.S. Using this approach you can change/add memory params directly from eclipse.
P.S.S. In Windows you should use setDomainEnv.cmd file and added line should be:
set USER_MEM_ARGS=%ECLIPSE_MEM_ARGS%
For Weblogic12:
Environment->Servers->[your_server]->Configuration/Server Start -> Arguments:
-Xms1024m -Xmx2048m
Restart the server:
Environment->Servers->[your_server]->Control/"Start/Stop" -> Suspend and then Start.
Check your memory:
Environment->Servers->[your_server]->Monitoring/Performance.
I have this VM with tomcat, java, and grails in it. I've been getting permgen errors so I looked around and found the solution:
set JAVA_OPTS="-Xms256m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m"
I use SSH to access the vm and type the arguments above. I suppose that would fix the problem. Thing is, I wanted to make sure that I did it correctly. So I searched again on how I could check the current permSize and this is the solution I got:
jinfo -flag MaxPermSize 6444
6444 is the pid, and as a response, I got this.
-XX:MaxPermSize=85983232
Question: Is the value of the maxPermSize in bytes? because, if it is, then that would mean that the java_opts command didn't work. I am expecting to get 512m but 85983232 bytes = 82 mb.. Or am I seeing it wrong..? Can anybody enlighten me on this? D:
You have to change the values in the CATALINA_OPTS option defined in the Tomcat Catalina start file. To increase the PermGen memory change the value of the MaxPermSize variable, otherwise change the value of the Xmx variable.
Linux & Mac OS: Open or create setenv.sh file placed in the "bin" directory. You have to apply the changes to this line:
export CATALINA_OPTS="$CATALINA_OPTS -server -Xms256m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m"
Windows:
Open or create the setenv.bat file placed in the "bin" directory:
set CATALINA_OPTS=-server -Xms256m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m
Don't put the environment configuration in catalina.bat/catalina.sh. Instead you should create a new file in CATALINA_BASE\bin\setenv.bat to keep your customizations separate of tomcat installation.
So you are doing the right thing concerning "-XX:MaxPermSize=512m": it is indeed the correct syntax. You could try to set these options directly to the Catalyna server files so they are used on server start.
Maybe this post will help you!
How to make sure that Tomcat6 reads CATALINA_OPTS on Windows?
Completely removed from java 8 +
Partially removed from java 7 (interned Strings for example)
source
There are lots of questions that ask this or a similar question.
They all give the command that has to be executed, what I don't understand is where do I write this command. I want to permanently increase the heap space for my tomcat apps.
I read this page http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html and it says under the Tomcat section
Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used. For example,
set CATALINA_OPTS=-Xms512m -Xmx512m (Windows, no "" around the value)
export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash, "" around the value)
setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh, "" around the value)
So I replaced the line
set CATALINA_OPTS=
with
set CATALINA_OPTS=-Xms512m -Xmx512m
But I still get the error.
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.OutOfMemoryError: Java heap space
java.lang.reflect.Array.multiNewArray(Native Method)
java.lang.reflect.Array.newInstance(Array.java:90)
nom.tam.util.ArrayFuncs.newInstance(ArrayFuncs.java:1028)
nom.tam.fits.ImageData.read(ImageData.java:259)
nom.tam.fits.Fits.readHDU(Fits.java:573)
controller.UploadServlet.retreiveFITSFileFields(UploadServlet.java:206)
controller.ScanServerFiles.doPost(ScanServerFiles.java:39)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
There is a mechanism to do it without modifying any files that are in the distribution. You can create a separate file %CATALINA_HOME%\bin\setenv.bat or $CATALINA_HOME/bin/setenv.sh and put your environment variables there. Further, the memory settings apply to the JVM, not Tomcat, so I'd set the JAVA_OPTS variable instead:
set JAVA_OPTS=-Xmx512m
First of all you cannot change the memory settings only for a tomcat application but rather for all tomcat instance.
If you are running tomcat from console (using startup.bat) you'll need to edit catalina.bat and play around with CATALINA_OPTS. For example:
set CATALINA_OPTS=-Xms512m -Xmx512m
Restarting tomcat will apply the new settings.
If you are still getting OutOfMemoryError you need to know how much memory does your application need at that particular moment (nom.tam.util.ArrayFuncs...). You'll either have to optimize the application or simply increase the memory provided to tomcat.
Your change may well be working. Does your application need a lot of memory - the stack trace shows some Image related features.
I'm guessing that the error either happens right away, with a large file, or happens later after several requests.
If the error happens right away, then you can increase memory still further, or investigate find out why so much memory is needed for one file.
If the error happens after several requests, then you could have a memory leak - where objects are not being reclaimed by the garbage collector. Using a tool like JProfiler
can help you monitor how much memory is being used by your VM and can help you see what is using that memory and why objects are not being reclaimed by the garbage collector.
Open the server tab in eclipse
right click open
click on open lauch configuration
Go to arguments
Here you can add in VM arguments after endorsed
-Xms64m -Xmx256m
You need to add the following lines in your catalina.sh file.
export CATALINA_OPTS="-Xms512M -Xmx1024M"
UPDATE : catalina.sh content clearly says -
Do not set the variables in this script. Instead put them into a script setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
So you can add above in setenv.sh instead (create a file if it does not exist).
Easiest way of doing is: (In Linux/Ububuntu e.t.c)
Go to tomcat bin directory:
cd /opt/tomcat8.5/bin
create new file under bin directory "setenv.sh" and save below mention entries in it.
export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx2048m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"
and issue command:
./catalina.sh run
In your catalina log file you can see entry like this:
INFO [main] VersionLoggerListener.log Command line argument: -Xms512m
INFO [main] VersionLoggerListener.log Command line argument: -Xmx2048m
INFO [main] VersionLoggerListener.log Command line argument: -XX:MaxPermSize=256m
Which confirms that above changes took place.
Also, the value of "Xms512m" and "-Xmx2048m" can be modified accordingly in the setenv.sh file.
Startup of tomcat could be done in two steps as well.
cd /opt/tomcat8.5/bin
Step #1
run ./setenv.sh
Step #2
./startup.sh
If you're using systemd edit:
/usr/lib/systemd/system/tomcat8.service
and set
Environment=CATALINA_OPTS="-Xms512M -Xmx2048M -XX:MaxPermSize=256m"
if you are using Windows, it's very simple. Just go to System Environnement variables (right-clic Computer > Properties > Advanced System Parameters > Environnement Variables); create a new system variable with name = CATALINA_OPTS and value = -Xms512m -Xmx1024m. restart Tomcat and enjoy!
For Windows Service, you need to run tomcat9w.exe (or 6w/7w/8w) depending on your version of tomcat.
First, make sure tomcat is stopped. Then double click on tomcat9w.exe. Navigate to the Java tab. If you know you have 64 bit Windows with 64 bit Java and 64 bit Tomcat, then feel free to set the memory higher than 512. You'll need to do some task manager monitoring to determine how high to set it. For most apps developed in 2019... I'd recommend an initial memory pool of 1024, and the maximum memory pool of 2048. Of course if your computer has tons of RAM... feel free to go as high as you want.
Also, see this answer: How to increase Maximum Memory Pool Size? Apache Tomcat 9
you can set this in catalina.sh as CATALINA_OPTS=-Xms512m -Xmx512m
Open your tomcat-dir/bin/catalina.sh file and add following line anywhere -
CATALINA_OPTS="$CATALINA_OPTS -Xms1024m -Xmx3024m"
and restart your tomcat
Just set this extra line in catalina.bat file
LINE NO AROUND: 143
set "CATALINA_OPTS=-Xms512m -Xmx512m"
And restart Tomcat service