Hello, I am getting OutOfMemory Errors. I have looked through the Forums and attempted to find similar problems. I have discovered many things there and attempted to incorporate them in my code.
What is happening is that I have a test harness which is calling the saveEventAndAlarm() method (listed below) 100,000 times. I am trying to determine performance characteristics, as well as determine what happens when I call the routine this many times. I am flushing, clearing, and closing my session in an attempt to get rid of the caches.
What I am seeing is that approximately 30K to 40K entries are entered, and then the OutOfMemoryError that is shown occurs.
One thing of note. The alarm that is passed is kept in a hashtable. This is done for quick access. The number of alarms is small, and in my test case, there are only two that are ever created. However, the same object is used over and over to do an update, as the time on the alarm needs to be updated.
I do not keep the event.
Am I doing something incorrectly?
Thank you,
Roger
Hibernate version:
2.1.6, 9.8.2004
JBoss
JBoss Version 3.2.3
The jboss_service.xml I am using
Code:
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends> <!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">
mappings/SVAlarm.hbm.xml,
mappings/SVAlarmEvent.hbm.xml
</attribute>
<attribute name="JndiName">java:/HibernateFactory</attribute>
<attribute name="Datasource">java:/MySqlDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="ShowSql">true</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>
</server>
Mapping documents: Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.cedarpointcom.safariview2.common.alarms">
<class name="SVAlarm" table="svalarms">
<id name="eid" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="name" not-null="true">
<column name="name" sql-type="char(25)"/>
</property>
<property name="severity" not-null="true">
<column name="severity" sql-type="char(25)"/>
</property>
<property name="entityType" not-null="true">
<column name="entitytype" sql-type="char(25)"/>
</property>
<property name="entityKey" not-null="true">
<column name="entitykey" sql-type="char(50)"/>
</property>
<property name="deviceId" not-null="true"> <!-- this should be fk to device -->
<column name="deviceid" sql-type="char(25)"/>
</property>
<property name="setState" not-null="true"/>
<property name="suppressState" />
<property name="timeCreated" not-null="true"/>
<property name="timeModified" not-null="true"/>
<property name="owner"> <!-- the user assigned to, users not stored in db-->
<column name="owner" sql-type="char(25)"/>
</property>
<property name="notes" />
<property name="managedObjType">
<column name="managedObjType" sql-type="char(25)"/>
</property>
<property name="managedObjKey">
<column name="managedObjKey" sql-type="char(50)"/>
</property>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.cedarpointcom.safariview2.common.alarms">
<class name="SVAlarmEvent" table="svevents" lazy="true">
<id name="eid" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="name" not-null="true">
<column name="name" sql-type="char(25)"/>
</property>
<property name="severity" not-null="true">
<column name="severity" sql-type="char(25)"/>
</property>
<property name="entityType" not-null="true">
<column name="entitytype" sql-type="char(25)"/>
</property>
<property name="entityKey" not-null="true">
<column name="entitykey" sql-type="char(50)"/>
</property>
<property name="deviceId" not-null="true">
<column name="deviceid" sql-type="char(25)"/>
</property>
<property name="timeStamp" not-null="true"/>
<property name="setAction" not-null="true"/>
<property name="reasonCode" not-null="true"/>
<property name="alarmId" not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
public class HibernateUtil
{
// TODO: find out if this is safe
static SessionFactory factory = null;
public static SessionFactory getSessionFactory() throws NamingException
{
if ( factory == null )
{
InitialContext initialContext = new InitialContext();
factory = (SessionFactory)initialContext.lookup("java:/HibernateFactory");
}
return factory;
}
public static Session getSession() throws SafariViewException
{
Session session = null;
try
{
SessionFactory factory = getSessionFactory();
session = factory.openSession();
}
catch(NamingException ne)
{
ne.printStackTrace();
throw new SafariViewException("UNABLE TO GET DB (HIBERNATE) SESSION FACTORY!",ne);
}
catch (HibernateException he)
{
he.printStackTrace();
throw new SafariViewException("UNABLE TO OBTAIN DB (HIBERNATE) SESSION!", he);
}
return session;
}
public static Transaction getTransaction(Session session) throws SafariViewException
{
Transaction tx = null;
try
{
tx = session.beginTransaction();
}
catch(HibernateException he)
{
he.printStackTrace();
try
{
session.close();
}
catch(HibernateException closeex)
{
closeex.printStackTrace();
throw new SafariViewException("Could Not Close Session: Transaction could not be created", closeex);
}
throw new SafariViewException("UNABLE TO BEGIN TRANSACTION", he);
}
return tx;
}
}
Code:
void saveEventAndAlarm(SVAlarmEvent event, SVAlarm alarm) throws SafariViewException
{
Session session = HibernateUtil.getSession();
session.clear();
Transaction tx = HibernateUtil.getTransaction(session);
boolean rollbackfailed = false;
try
{
session.saveOrUpdate(alarm);
System.out.println("alarm Eid is " + alarm.getEid());
event.setAlarmId(alarm.getEid());
session.saveOrUpdate(event);
tx.commit();
}
catch(HibernateException he)
{
he.printStackTrace();
try{ tx.rollback(); }
catch(HibernateException rollbacke)
{
rollbackfailed = true;
rollbacke.printStackTrace();
}
throw new SafariViewException("Could Not Save Event and Alarm", he);
}
finally
{
try
{
session.flush();
session.clear();
session.close();
}
catch(HibernateException closeException)
{
StringBuffer error = new StringBuffer("Call to Session.Close() failed:");
if ( rollbackfailed )
error.append(" A Rollback Failure also indicates that the Event and Alarm were not saved.");
throw new SafariViewException(error.toString(), closeException);
}
}
}
Full stack trace of any exception that occurs:
16:36:10,763 INFO [STDOUT] Error occurred during test: javax.transaction.Transa
ctionRolledbackException: null; nested exception is:
java.lang.OutOfMemoryError
16:36:10,763 ERROR [STDERR] javax.transaction.TransactionRolledbackException: nu
ll; nested exception is:
java.lang.OutOfMemoryError
16:36:10,763 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.i
nvokeNext(AbstractTxInterceptor.java:214)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWit
hTransactions(TxInterceptorCMT.java:267)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:128)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.inv
oke(SecurityInterceptor.java:118)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(L
ogInterceptor.java:191)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.plugins.ProxyFactoryFinderInter
ceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.inter
nalInvoke(StatelessSessionContainer.java:331)
16:36:10,779 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java
:700)
16:36:10,779 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor37.invoke(
Unknown Source)
16:36:10,779 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
16:36:10,779 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
24)
16:36:10,779 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatc
her.invoke(ReflectedMBeanDispatcher.java:284)
16:36:10,779 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MB
eanServerImpl.java:546)
16:36:10,779 ERROR [STDERR] at org.jboss.invocation.local.LocalInvoker.invok
e(LocalInvoker.java:101)
16:36:10,779 ERROR [STDERR] at org.jboss.invocation.InvokerInterceptor.invok
e(InvokerInterceptor.java:90)
16:36:10,779 ERROR [STDERR] at org.jboss.proxy.TransactionInterceptor.invoke
(TransactionInterceptor.java:46)
16:36:10,779 ERROR [STDERR] at org.jboss.proxy.SecurityInterceptor.invoke(Se
curityInterceptor.java:45)
16:36:10,779 ERROR [STDERR] at org.jboss.proxy.ejb.StatelessSessionIntercept
or.invoke(StatelessSessionInterceptor.java:100)
16:36:10,779 ERROR [STDERR] at org.jboss.proxy.ClientContainer.invoke(Client
Container.java:85)
16:36:10,779 ERROR [STDERR] at $Proxy52.makeRequest(Unknown Source)
16:36:10,779 ERROR [STDERR] at com.cedarpointcom.safariview2.server.alarms.A
larmManagerEJB.test(Unknown Source)
16:36:10,779 ERROR [STDERR] at com.cedarpointcom.safariview2.server.RequestM
anagerEJB.initialize(Unknown Source)
16:36:10,779 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
16:36:10,779 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
16:36:10,779 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
16:36:10,794 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
24)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer$Conta
inerInterceptor.invoke(StatelessSessionContainer.java:683)
16:36:10,794 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedCo
nnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.StatelessSessionInstanc
eInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.i
nvokeNext(AbstractTxInterceptor.java:84)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWit
hTransactions(TxInterceptorCMT.java:267)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:128)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.inv
oke(SecurityInterceptor.java:118)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(L
ogInterceptor.java:191)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.plugins.ProxyFactoryFinderInter
ceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.inter
nalInvoke(StatelessSessionContainer.java:331)
16:36:10,794 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java
:700)
16:36:10,794 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
16:36:10,794 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
16:36:10,794 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
16:36:10,794 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
24)
16:36:10,794 ERROR [STDERR] at org.jboss.mx.capability.ReflectedMBeanDispatc
her.invoke(ReflectedMBeanDispatcher.java:284)
16:36:10,810 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MB
eanServerImpl.java:546)
16:36:12,278 ERROR [STDERR] at org.jboss.invocation.local.LocalInvoker.invok
e(LocalInvoker.java:101)
16:36:12,294 ERROR [STDERR] at org.jboss.invocation.InvokerInterceptor.invok
e(InvokerInterceptor.java:90)
16:36:12,294 ERROR [STDERR] at org.jboss.proxy.TransactionInterceptor.invoke
(TransactionInterceptor.java:46)
16:36:12,294 ERROR [STDERR] at org.jboss.proxy.SecurityInterceptor.invoke(Se
curityInterceptor.java:45)
16:36:12,294 ERROR [STDERR] at org.jboss.proxy.ejb.StatelessSessionIntercept
or.invoke(StatelessSessionInterceptor.java:100)
16:36:12,294 ERROR [STDERR] at org.jboss.proxy.ClientContainer.invoke(Client
Container.java:85)
16:36:12,294 ERROR [STDERR] at $Proxy44.initialize(Unknown Source)
16:36:12,294 ERROR [STDERR] at com.cedarpointcom.safariview2.common.SafariVi
ewStartupService$InitializeSafariViewThread.run(Unknown Source)
16:36:12,294 ERROR [STDERR] Caused by: java.lang.OutOfMemoryError
16:36:12,294 ERROR [STDERR] java.lang.OutOfMemoryError
Name and version of the database you are using:
MYSql - version 4.0.20d
Debug level Hibernate log excerpt: