I have developed enterprise application with hibernate framework.Application hangs when there is surge in the number of users(when user count is more than 200).I have tried the following methods but still the problem persists.
1)C3PO connection pooling(Prior no connection pooling used)
2)Increased hibernate connection pool size to 300(Before value 100)
3)Changed getCurrentSession methods to openSession
hibernate.cfg.xml file has connection.pool_size=300
Most of the application queries are called using this method -
@Override
public List getLovServiceSqlParam(String query, Object[] obj) {
// TODO Auto-generated method stub
Session session = null;
if (this.getHibernateTemplate() != null && query != null
&& query.length() > 0) {
try
{
session = this.getHibernateTemplate().getSessionFactory().openSession();
SQLQuery query1 = session.createSQLQuery(query);
for(int i=0;i<obj.length;i++)
{
query1.setParameter(i, obj[i]);
}
result = query1.list();
session.close();
}
catch (DataAccessException e) {
e.printStackTrace();
throw e;
}
finally
{
if (session != null && session.isOpen()) {
session.close();
}
}
}
return result;
}
That kind of situation is not solved by looking at code but by running a cpu sampling tool (like jvisualvm, free and included in oracle JVM package, look there :
$JAVA_HOME/bin/jvisualvm
), on your application under load.Look at where your UI threads are spending most of their time, and optimise these part, one after another.
It might be due to no more connection to the database, or because of contention on some queries, or something else, totally unexpected. You'll know only after running the cpu sampling analysis.
To do this,
Sampler
tab, then click theCPU
button,Snapshot
button.