Hibernate web application

41 views Asked by At

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;
}
1

There are 1 answers

1
Thierry On

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,

  • Connect jvisualvm to an application under load (might not be easy to get an environnement which displays the same behavior as the production environnement, but it could be even harder to get a jvisualvm access to the production environnement, depending on IT rules where you work),
  • Switch to the Sampler tab, then click the CPU button,
  • Trigger an action on your UI (normally this action should have the unexpected behavior (too slow ?)).
  • Once finished, click on the Snapshot button.
  • From there find your UI thread (might not be easy), and then look where it spend most of its time.
  • Optimize this part