English 中文(简体)
Hibernate :OutOfMemoryError: PermGenspace [duplicate]
原标题:Hibernate :OutOfMemoryError: PermGen space [duplicate]

could anyone say what s wrong with my application?

public class HibernateUtil {
    private static final SessionFactory sessionFactory;

    static {
        try {
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

public boolean insertUser(User user) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        session.beginTransaction();
        session.save(user);
        session.getTransaction().commit();

    } catch (HibernateException he) {
        session.getTransaction().rollback();
        return false;
    }finally{
        if (session != null){
            session.close();
        }
    }

    return true;
}

This is the only method i call to insert an user in the database, and then if i try to insert another one, launch this exception:

Initial SessionFactory creation failed.java.lang.OutOfMemoryError: PermGen space

UPDATE: I don t know if there s something in hibernate.cfg but here it go:

<?xml version="1.0" encoding="UTF-8"?>

org.hibernate.dialect.MySQLDialect com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/XXXXX XXXX XXXXc thread

    <!-- Connection pool C3P0 -->
    <property name="hibernate.c3p0.acquire_increment">2</property>
    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">100</property>
    <property name="hibernate.c3p0.timeout">20</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.idle_test_period">60</property>

    <!-- To show sql output on the screen -->
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.format_sql">true</property>

    <!-- Mapping the tables in my schema -->
    ...

</session-factory>

为什么会发生这种情况以及如何纠正?

Best regards, Valter Henrique.

问题回答

非常常见于Hibernate和大型项目。 PermGen是这些班级的储存地(这不是“Heap!”)。 现在,每组都属于PermGen,如果项目足够庞大,64MB的缺省规模就不足。

产生于出口国 飞机上为贵实体开设的班级。 这可能是你在解放的背景下发现这一错误的原因。 生成的班级也可填充大首。

一般建议: 如果这不是一个玩具项目,那么只增加您的Perm Gen with -XX:MaxPermSize=96M,而且你可以安全使用。

还请指出,由于多种原因,网络应用集装箱可能会出现卸载申请的问题(服务器式板块组合是一个共同问题),所有生成的Hibernates级将每台网络再一次创建。 在这种情况下,更好地重新启用服务器。

此前我曾有过这一问题,发现这一问题是由于先前在C3PO集合数据库中的记忆泄露造成的,而该数据库并未正确关闭。

因此,解决办法是人工硬地重新制定并关闭C3PO数据来源,而这种数据来源尚未开发。

因此,在一种习俗中,在“......”方法中添加以下代码:

Set<PooledDataSource> pooledDataSourceSet = (Set<PooledDataSource>) C3P0Registry.getPooledDataSources();

    for (PooledDataSource dataSource : pooledDataSourceSet) {
        try {
            dataSource.hardReset();
            dataSource.close();
        } catch (SQLException e) {
            // note - do not use log4j since it may have been unloaded by this point
            System.out.println("Unable to hard reset and close data source.", e);
        }
    }

“java.lang.OutOfMemoryError: PermGenspace”例外的最常见根源是储存泄露,其起因是多次热量转换成一个网络集装箱。

  • 您的网络集装箱是否经过热量改动?

  • 如果你重新启用网络集装箱,问题是否“消失”?

如果对这两个问题的答复是“是”,那么机会就是这是你的问题。

有三个解决办法:

  • Don t 热量。 或者至少更经常地完全重新启用你的网络集装箱。

  • 利用<代码>-XX:MaxPermSize=......,增加对 per粒的限制

  • 跟踪和确定实际上造成储存泄漏的任何情况。

存在着高负荷的臭名昭著的泄漏综合症。 保留提及一些热载舱旧版本所产生的一个物体,将泄露all<>>>m>,由班级载荷装载的类别及其所有静态。


@Daniel称,Hibernate产生大量代用班,使用永久性空间,并且可以提高基因肥皂的规模。 我期望这样做能够稳定下来,即“武装起来”的申请不会产生任何更多的代用类别。 然而,由于热负荷导致反复发生,代理班如上所示正在泄漏。

You could increase permanent generation size , you should add -XX:MaxPermSize=128m as jvm option. But it is really strange that default perm generation size is not enough for your program..





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...