用hibernate优化java数据库连接
我正在处理hibernate应用程序,我使用hibernate.c3po
配置来调整可能的连接数。我的问题是,一些用户抱怨数据库连接在使用几分钟后崩溃。在cfg
文件中,我额外使用了以下行:
<property name="hibernate.c3p0.max_size">5</property>
<property name="hibernate.c3p0.min_size">1</property>
在事务中,我始终使用currentSession
:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = HibernateUtil.getTransaction(session);
try
{
tx.begin();
session.update(u);
tx.commit();
}
catch (Exception e)
{
tx.rollback();
e.printStackTrace();
}
为了使数据库连接可靠,适当的改进/优化是什么?
我也应该使用hibernate.c3p0.timeout
属性吗?在这种情况下,其影响如何
如果我使用openSession
而不是getCurrentSession
会更好吗?我的印象是session
与connection
无关。我说得对吗
共 (0) 个答案