We have developed a gwt-hibernate multi database application which is 
running on Glassfish and using Oracle datatabase. After a connection to 
a default database which is addressed by a default persistence unit like 
the following:

<persistence-unit name="DefaultDBConnection" 
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" 
value="org.hibernate.dialect.Oracle8iDialect" />
<property name="hibernate.connection.driver_class" 
value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.username" value="user" />
<property name="hibernate.connection.password" value="******************" />
<!-- <property name="hibernate.hbm2ddl.auto" value="update" /> -->
<property name="hibernate.connection.url" 
value="jdbc:oracle:thin:@server:1521:orcl" />
<property name="hibernate.show_sql" value="true" />
<!-- <property name="hibernate.format_sql" value="true"/> -->
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.cache.provider_class" 
value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.query.plan_cache_max_strong_references" value="8" 
/>
<property name="hibernate.query.plan_cache_max_soft_references" value="16" 
/>
<property name="connection.provider_class" 
value="org.hibernate.connection.C3P0ConnectionProvider" /> 
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="200" />
<property name="hibernate.c3p0.timeout" value="300" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
<property name="hibernate.generate_statistics" value="true" /> 
</properties>
</persistence-unit>

the database selection is done by the user login through our HibernateGwt 
class which connects to the proper database through a different persistence 
unit.
The EntityManager to interact with the proper database is then opened-taken 
by the following instructions in the gwt RemoteServiceServlet:

  EntityManager session = getSession();

where 

private javax.persistence.EntityManager getSession() {
return HibernateGwt.getInstance().getEntityManager(this);
}

and "this" is a com.google.gwt.user.server.rpc.RemoteServiceServlet, while 


        private static HibernateGwt singleton = new HibernateGwt();

private HashMap<String,javax.persistence.EntityManagerFactory> 
factoryCollection = new 
HashMap<String,javax.persistence.EntityManagerFactory>();

private ThreadLocalUtil entityManagerCollection = new ThreadLocalUtil(); 


public javax.persistence.EntityManager getEntityManager(Object service) {
 ThreadLocal myTdl;
javax.persistence.EntityManager entityManager;

                //to get the right persistence name from the user logged in 
which is stored as a session variable
String persistenceUnit = getPersistenceUnit(service); 
 entityManager = (EntityManager) 
entityManagerCollection.getThreadVariable(persistenceUnit);
if (entityManager == null || !entityManager.isOpen()) {
entityManager = getFactory(persistenceUnit).createEntityManager();
entityManagerCollection.setThreadVariable(persistenceUnit, entityManager);
}
return entityManager;
}

At user logout we close the connection as follow:


          HibernateGwt.getInstance().close(null);

where 

public void close(String persistenceUnit) {
if (persistenceUnit == null)
persistenceUnit = getPersistenceUnit();
 closeEntityManager(persistenceUnit);
 if (factoryCollection.containsKey(persistenceUnit)){
javax.persistence.EntityManagerFactory factory = 
factoryCollection.get(persistenceUnit);
if (factory != null) {
factory.close();
factory = null;
}
factoryCollection.remove(persistenceUnit);
}
}

and

public void closeEntityManager(String persistenceUnit) {
javax.persistence.EntityManager entityManager;
 if (persistenceUnit == null)
persistenceUnit = getPersistenceUnit();
 entityManager = (EntityManager) 
entityManagerCollection.getThreadVariable(persistenceUnit);
if (entityManager != null && entityManager.isOpen()) {
entityManager.close();
}
entityManagerCollection.setThreadVariable(persistenceUnit, null);
}

Please, can someone help us understand what we are doing wrong to not let 
Glassfish release resources and fall into a degrade of performace until we 
restart it?


-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to