Hibernate C3P0 hangs when reaches maxpoolsize even with maxidletime set
Not really understanding these setting too well at the moment, wondering
if someone could point me in the right direction.
I have the following, which I thought was basically saying
1: Minimum number of pooled connections = 5 2: Maximum number of pooled
connections = 10 3: How long an idle connection should stay open, 5
seconds (at which point it's closed and becomes available again.
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/testdb" />
<property name="user" value="root" />
<property name="password" value="password" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="10" />
<property name="maxIdleTime" value="5" />
<property name="maxStatements" value="0" />
</bean>
But in my simple little test app, that runs a simple select where id = 1
on a test table, as soon as I get to my 11th 'search', it app hangs.
Why am I maxed to just 10 connections, even if I wait well over 5 seconds,
why are none of the connections freed up?
-- Snippets of my classes:
public Object readObject(SessionFactory sessionFactory, String hql,
Map<String,Object> args) {
session = this.openHibernateSession(sessionFactory);
Query query = session.createQuery(hql);
Iterator<Entry<String, Object>> it = args.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Object> entry = it.next();
query.setParameter(entry.getKey(), entry.getValue());
}
@SuppressWarnings("unchecked")
List<Object> list = query.list();
this.closeHibernateSession(sessionFactory); // I don't even know if I
should need this!
if (list!=null && list.size() > 0) {
return list.get(0);
} else {
log4j.warn("readObject: List is NULL.");
return null;
}
}
protected Session openHibernateSession(SessionFactory sessionFactory) {
Session session = null;
try {
session = sessionFactory.getCurrentSession();
} catch (HibernateException ex) {
session = sessionFactory.openSession();
}
return session;
}
protected void closeHibernateSession(SessionFactory sessionFactory){
Session session;
try {
if (sessionFactory.getCurrentSession()!=null) {
session = sessionFactory.getCurrentSession();
session.close();
}
} catch (HibernateException ex) {
log4j.warn("Failed to close current session, set session to
null.", ex);
session = null;
}
}
Cheers in advance.
No comments:
Post a Comment