【问题标题】:GORM/Hibernate + GC overhead limit exceeded超过 GORM/Hibernate + GC 开销限制
【发布时间】:2016-02-04 17:01:36
【问题描述】:

以下 remove() 方法导致“超出 GC 开销限制”。当从 A 或 B 或 C 中删除 ABC 中存在的关联时。你能告诉我有什么问题吗? 注意 - ABC 是 A、B、C 的映射表

堆栈跟踪如下: Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded at java.util.jar.Attributes.read(Attributes.java:394) at java.util.jar.Manifest.read(Manifest.java:199) at java.util.jar.Manifest.<init>(Manifest.java:69) at java.util.jar.JarFile.getManifestFromReference(JarFile.java:185) at java.util.jar.JarFile.getManifest(JarFile.java:166) at java.net.URLClassLoader.defineClass(URLClassLoader.java:416) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at org.codehaus.groovy.tools.RootLoader.oldFindClass(RootLoader.java:171) at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:143) at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

@Resource() 
@EqualsAndHashCode 
class ABC {
    static belongsTo = 
        [
            a: A, 
            b: B, 
            c: C
        ]

    def remove(){
        this.a?.removeFromBC(this)
        this.b?.removeFromAC(this)
        this.c?.removeFromAB(this)
        this.delete()
    }

@Resource()
class C {
    Collection<ABC> aB
    static hasMany = [aB: ABC]
    static constraints = {
        aB cascade: "all-delete-orphan", nullable: true
    }
}

@Resource()
class B {
    Collection<ABC> aC
    static hasMany = [aC: ABC]
    static constraints = {
        aC cascade: "all-delete-orphan", nullable: true
    }
}

@Resource()
class A {
    Collection<ABC> bC
    static hasMany = [bC: ABC]
    static constraints = {
        bC cascade: "all-delete-orphan", nullable: true
    }
}

【问题讨论】:

    标签: grails grails-orm hibernate-mapping


    【解决方案1】:

    不,该方法没有触发 OOME,运行时分配的堆空间太少。增加服务器的内存。

    【讨论】:

    • 你是对的。不是这个代码。问题是数据。 C 是一个小型查找表,ABC 可以为 C 中的特定行有很多行。所以this.c?removefromAB(this) 导致select .. from ABC where c.id=,它获取了很多行(以百万计)并导致了这个问题。我能做些什么不同的事情?
    • 您可以通过不使用集合来避免此类问题。观看此演讲以了解详细信息和解决方法:infoq.com/presentations/GORM-Performance
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 2020-02-26
    • 1970-01-01
    相关资源
    最近更新 更多