JAXB - Tomcat服务器上的permGen错误

时间:2009-09-20 00:57:15

标签: tomcat jaxb permgen

运行已部署的应用时出现以下错误。由于错误,似乎JAXB正在造成它。请建议。

java.lang.OutOfMemoryError: PermGen space
    com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createClassInfo(RuntimeModelBuilder.java:99)
    com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createClassInfo(RuntimeModelBuilder.java:70)
    com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:228)
    com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:89)
    com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:70)
    com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:198)
    com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:84)
    com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:70)
    com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:304)
    com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:319)
    com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:430)
    com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277)
    com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
    com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
    com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
    javax.xml.bind.ContextFinder.find(ContextFinder.java:376)
    javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
    javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
    MyJava.GetUserProfile.user(GetUserProfile.java:87)
    com.myapp.struts.TokenDirected.execute(TokenDirected.java:81)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

4 个答案:

答案 0 :(得分:1)

在Tomcat 5.5中遇到同样的问题 JAXB会为您造成大量内存泄漏,因为它会在服务器中创建大量静态变量。

参考文献: http://blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java http://blogs.oracle.com/fkieviet/entry/how_to_fix_the_dreaded

答案 1 :(得分:0)

首先增加烫发空间的大小。 This link向您展示如何。

使用Visual GC监控您的内存使用情况,看看它有何帮助。

如果没有,请摆脱JAXB。正是出于这个原因,我回避它。最好是手工制作你的OXM而不是依靠它。

答案 2 :(得分:0)

它与JAXB无关,但您的Tomcat需要更多来自JVM的内存,因此请使用类似

的内容
-Xms128m -Xmx512m -XX:128m

答案 3 :(得分:0)

问题与JaxBContext有关。每次使用新上下文时都会加载新类。如果你重复使用你的上下文,一切都会好的。

duffyno是对的:)