4

I have a Spring MVC WAR file that works perfectly in my local machine (program and website).

Once I upload the file into the server (a Tomcat 7) and try to access it, the catalina log file indicates java.lang.OutOfMemoryError.

I have tried modifying the memory in the Arguments tab of Eclipse IDE's Run > Run Configurations section by appending -Xmx2048m or -Xmx1024m to the VM Arguments section before exporting but neither did any changes except the first resulted into a

Error occurred during initialization of VM
Could not reserve enough space for object heap

in my local machine.

Here is the full log file from my initial visit to the site:

12 25, 13 6:16:23 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-11032"]
12 25, 13 6:16:23 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 658 ms
12 25, 13 6:16:23 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
12 25, 13 6:16:23 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.26
12 25, 13 6:16:23 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /home/username/tomcat7/webapps/project.war
12 25, 13 6:16:23 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/home/username/tomcat7/webapps/project/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
12 25, 13 6:16:40 PM org.apache.catalina.startup.HostConfig deployWARs
SEVERE: Error waiting for multi-thread deployment of WAR files to complete
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
  at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
  at java.util.concurrent.FutureTask.get(FutureTask.java:83)
  at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:751)
  at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:471)
  at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1412)
  at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:312)
  at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
  at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
  at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:401)
  at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:346)
  at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1145)
  at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:782)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.OutOfMemoryError: Java heap space
  at org.apache.tomcat.util.bcel.classfile.LineNumberTable.<init>(LineNumberTable.java:68)
  at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:144)
  at org.apache.tomcat.util.bcel.classfile.Code.<init>(Code.java:86)
  at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:140)
  at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:58)
  at org.apache.tomcat.util.bcel.classfile.Method.<init>(Method.java:72)
  at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:268)
  at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:128)
  at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2032)
  at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1923)
  at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1891)
  at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1877)
  at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
  at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
  at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
  at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
  at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
  at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
  at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
  at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
  at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
  ... 5 more
12 25, 13 6:16:41 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-11032"]
12 25, 13 6:16:45 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 21778 ms

How do I solve this?

  • You've just asked the same question a while ago. – Prasad Dec 25 '13 at 10:26
  • @JavaLearner, hello yes the one you suggested before which I mentioned here had its error not appear first because I had a server port error but it is showing now again. Please help me. –  Dec 25 '13 at 10:28
  • 4
    You need to increase the heap memory on the JVM that is used by the server, not in your eclipse. – Zyga Dec 25 '13 at 10:30
  • @Zyga: post your comment as an answer. – Ralph Dec 25 '13 at 10:34
  • @Zyga, thank you and is there a specific file that I can configure this? I tried searching for a `bin/catalina.bat` or similar file but my server tomcat folder does not have it. –  Dec 25 '13 at 10:37

3 Answers3

3

Like said in the comments section, you have to increase heap size on the JVM that is used by the server, not in your eclipse (as that only has the effect when you run it locally).

So try setting that to -Xmx512m or -Xmx1024m (or whatever else you need).

If you dont know how to do this let me know what version of Tomcat you are running and the platform (Linux, Windows etc).

Zyga
  • 2,367
  • 3
  • 22
  • 32
  • Thank you. It's a `Tomcat 7` –  Dec 25 '13 at 10:39
  • 1
    This post shows you how to do it. Hope this helps, any issues let me know. http://stackoverflow.com/questions/6897476/tomcat-7-how-to-set-initial-heap-size-correctly – Zyga Dec 25 '13 at 10:41
  • Okay so I found a `/root/tomcat/bin/setenv.sh` file. Is it correct that I just need to append the line `export CATALINA_OPTS="-Xms512M -Xmx1024M"` there? –  Dec 25 '13 at 10:45
  • 1
    You should be able to put just CATALINA_OPTS="-Xms512M -Xmx1024M" and then restart the server. – Zyga Dec 25 '13 at 10:49
1

Try to increase heap size of JVM.

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size

For Ex. -Xms(minimum size) and -Xmx(maximum size)

-Xms64m -Xmx256m
Prasad
  • 1,188
  • 3
  • 11
  • 29
0

I got this error in Amazon AWS ubuntu server - Tomcat 7

I solved the issue by first locating my tomcat catalina.sh file and updating the following line:

locate catalina.sh

/usr/share/tomcat7/bin/catalina.sh

sudo vi /usr/share/tomcat7/bin/catalina.sh

add the following line after the top comments:

CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"
Rose
  • 2,792
  • 4
  • 28
  • 42