以前都是正常的Tomcat 7服务器,在增加了一个新工程后,无法正常访问,查看日志:
1 |
$ cat /var/log/tomcat7/catalina.out |
可以看到如下错误信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
SEVERE: A child container failed during start java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:188) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128) 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.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.OutOfMemoryError: Java heap space at java.util.zip.InflaterInputStream.<init>(InflaterInputStream.java:88) at java.util.zip.ZipFile$ZipFileInflaterInputStream.<init>(ZipFile.java:389) at java.util.zip.ZipFile.getInputStream(ZipFile.java:370) at java.util.jar.JarFile.getInputStream(JarFile.java:412) at org.apache.tomcat.util.scan.FileUrlJar.getEntryInputStream(FileUrlJar.java:96) at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1922) 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) ... 7 more |
说明Tomcat在增加新工程后,内存不足了。
解决方法如下:
修改/etc/default/tomcat7
文件:
1 |
$ sudo vim /etc/default/tomcat7 |
找到如下信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# The home directory of the Java development kit (JDK). You need at least # JDK version 1.5. If JAVA_HOME is not set, some common directories for # OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried. #JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk # You may pass JVM startup parameters to Java here. If unset, the default # options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC # # Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved # response time). If you use that option and you run Tomcat on a machine with # exactly one CPU chip that contains one or two cores, you should also add # the "-XX:+CMSIncrementalMode" option. JAVA_OPTS="-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC" |
可以看到,目前限制的内存最大值为128MB,-Xmx128m
,调整到256MB后重启Tomcat7。
1 |
$ sudo service tomcat7 restart |
解决问题。