JVM虚拟内存调整

这次真的是为了调一个环境花费两三天的时间,太纠结了,现在每天都要去听实习那个没什么意思的课程,只能每天中午午休的时候和晚上放学回来抓紧时间写一点,每次都是稍稍有点状态思路刚活跃时间就到了,又要走人

这次异常调到后来,感觉弯路走了很多,于是开始有意识的用记事本记录下来,最开始的时候放在 MyEclispe 自带的 tomcat 5.5 里面,可以启动的起来,但是由于 5.5 不支持使用注释语法,于是自己换了个 tomcat 7 ,于是报异常,异常是

信息: validateJarFile(D:DocumentscodeMyEclipse86.metadataapache-tomcat-7.0.29webappsNeddyTravelWEB-INFlibel-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
2012-7-17 22:02:29 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(D:DocumentscodeMyEclipse86.metadataapache-tomcat-7.0.29webappsNeddyTravelWEB-INFlibservlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax rvlet/Servlet.class
2012-7-17 22:02:29 org.apache.tomcat.util.digester.Digester endElement
严重: End event threw exception
java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addFilter

而当时的 web.xml 是这样子的

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>NeddyTravel</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext-*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <filter>
    <display-name>Post</display-name>
    <filter-name>Post</filter-name>
    <filter-class>travel.filter.Post</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>Post</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

感觉上应该是没有什么问题,出于慎重还是二分法注释掉了很多,最后基本上整个文件注释掉了,还是不行,异常变成这样

2012-7-19 18:00:30 org.apache.catalina.startup.HostConfig deployDirectories
严重: Error waiting for multi-thread deployment of directories to completehostConfig.deployWar=Deploying web application archive {0}
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.deployDirectories(HostConfig.java:1023)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1413)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:313)
	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:1140)
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:785)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	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:619)
Caused by: java.lang.OutOfMemoryError: Java heap space
	at java.io.DataInputStream.readUTF(DataInputStream.java:644)
	at java.io.DataInputStream.readUTF(DataInputStream.java:547)
	at org.apache.tomcat.util.bcel.classfile.ConstantUtf8.<init>(ConstantUtf8.java:48)
	at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:129)
	at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:60)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:209)
	at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:119)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2066)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1942)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1908)
	at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1893)
	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1296)
	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:346)
	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:5173)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	... 5 more

报内存溢出,一开始认为 tomcat 默认的内存应该是够的,于是就没有往调内存方面想,后来实在折腾不过,回到这个地方来,开始思考是否真的是 tomcat 的内存不够,写了这个代码用来查看虚拟机内存,

Runtime runtime = Runtime.getRuntime();
out.println(runtime.totalMemory()/1024);
out.println(runtime.freeMemory()/1024);

发现内存初始只有 8M 左右,真的挺小,于是上网搜,根据方法,在 MyEclipse 的下配了 JVM 的内存,就好了

折腾了许久的问题,居然这么傻逼,真是无颜面对江东父老啊

Leave a Reply

Your email address will not be published. Required fields are marked *