Hi!
I have got a problem with method execution time in my concurrency application.
My hibernate configuration is:
Code:
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<property name="hibernate.connection.url">@hibernate.connection.url@</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">@hibernate.connection.user@</property>
<property name="hibernate.connection.password">@hibernate.connection.password@</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">59</property>
<property name="hibernate.c3p0.acquire_increment">3</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1</property>
My dao methos is:
Code:
@SuppressWarnings(value = "unchecked")
public List<DBPaymentsTreeEntity> getPaymentsTree(DBTerminalsEntity terminal, int parent_id, long cardnumber) {
long start = System.currentTimeMillis();
try {
Session session = sessionFactory.getCurrentSession();
Query query = session.createSQLQuery("some_sql_query")
.setInteger("terminal", terminal.getId())
.setInteger("payments_id", parent_id);
List<Object[]> rs = query.list();
session.getTransaction().commit();
logger.info(Thread.currentThread().getName() + " [" + terminal.getName() + "] - " + (System.currentTimeMillis() - start) + " msecs ");
return ret;
} catch (HibernateException e) {
logger.error("", e);
sessionFactory.getCurrentSession().getTransaction().rollback();
return null;
}
}
My test is:
Code:
for (int i = 0; i < 1000; i++) {
new Thread(new MyRunnable()).start();
}
, where MyRunnable invoke getPaymentsTree method.
Test result is:
22/10/2010 15:05:44 : Thread-353 [INF10347] - 1937 msecs
22/10/2010 15:05:44 : Thread-149 [INF10143] - 1984 msecs
22/10/2010 15:05:44 : Thread-736 [INF10730] - 1797 msecs
...
22/10/2010 15:05:46 : Thread-450 [INF10444] - 3578 msecs
22/10/2010 15:05:46 : Thread-731 [INF10725] - 3469 msecs
22/10/2010 15:05:46 : Thread-515 [INF10509] - 3578 msecs
...
22/10/2010 15:05:47 : Thread-204 [INF10198] - 5328 msecs
22/10/2010 15:05:47 : Thread-904 [INF10898] - 5110 msecs
22/10/2010 15:05:47 : Thread-408 [INF10402] - 5282 msecs
So, we can see that the time always increases.
When I use my hiberante configuration and Spring with @Transactional annotation on dao method the result is:
22/10/2010 15:19:13 : Thread-6 [----] - 594 msecs
22/10/2010 15:19:13 : Thread-514 [INF10508] - 1141 msecs
22/10/2010 15:19:13 : Thread-521 [INF10515] - 1219 msecs
...
22/10/2010 15:19:13 : Thread-407 [INF10401] - 313 msecs
22/10/2010 15:19:13 : Thread-818 [INF10812] - 266 msecs
22/10/2010 15:19:13 : Thread-915 [INF10909] - 328 msecs
...
22/10/2010 15:19:16 : Thread-1000 [INF10994] - 78 msecs
22/10/2010 15:19:16 : Thread-368 [INF10362] - 78 msecs
22/10/2010 15:19:16 : Thread-216 [INF10210] - 78 msecs
What I can do to have the same result in Hibernate without Sping?