小编典典

WAR文件在Tomcat服务器中引发OutOfMemoryError

tomcat

我有一个Spring MVC WAR文件,该文件在我的本地计算机(程序和网站)中可以正常运行。

一旦我将文件上传到服务器(a Tomcat 7)并尝试访问它,catalina日志文件就会显示java.lang.OutOfMemoryError

我尝试在导出之前通过Arguments在Eclipse IDE的Run > Run Configurations部分的选项卡中添加-Xmx2048m-Xmx1024m来修改Eclipse IDE的部分中的内存,VM Arguments但是除了第一个导致的更改外,都没有做任何更改

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

在我的本地机器上。

这是我初次访问该站点时的完整日志文件:

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

我该如何解决?


阅读 334

收藏
2020-06-16

共1个答案

小编典典

如注释部分中所述,您必须增加服务器使用的JVM上的堆大小,而不要增加eclipse中的堆大小(因为这仅在本地运行时才起作用)。

因此,请尝试将其设置为-Xmx512m-Xmx1024m(或您需要的其他选项)。

如果您不知道如何执行此操作,请让我知道您正在运行哪个版本的Tomcat和平台(Linux,Windows等)。

2020-06-16