100 threads are concurrently querying the database with the same query.
Each thread gets a hibernate session independently of the other sessions (via the standard ThreadLocal.get() lookup followed by a sessionFactory.openSession() if its not there) and closes it in its finally block.
On each thread, I time how long it takes for the criteria.list() method to return. Without C3P0 in the configuration file, I notice that the wait times for each thread's criteria.list() call grow exponentially from milliseconds to up to 30 seconds for the final thread.
So it would appear that two threads cannot call criteria.list() at the same time within the same JVM? Is this true? If not... read on...
Figuring it may have something to do with used up connections from my 100 concurrent threads, I turned on C3P0 with a connection pool of 100. Re-ran my test, and the same exact thing happened with nearly the same numbers.
What am I missing here? (I am using MySQL)
Code:
in my hibernate.cfg.xml file:
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property>
<property name="c3p0.max_size">10</property>
<property name="c3p0.max_statements">10</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property>
Is this sort of FIFO behavior expected on a criteria.list() regardless of how many sessions are calling it?
Thank you in advance.
Mark