我正在使用带有Hibernate的jboss 4.2。 我需要记录事务持续时间,因此我有关于事务完成或回滚所需的平均时间的统计信息。 我的另一个问题是jboss JTA(arjuna)中止长时间运行的事务,所以我需要知道在那里配置什么超时。
答案 0 :(得分:0)
我认为您应该创建一个计时器来计算事务开始和结束之间的时间。实现这一目标的可能性是:
EntityManager em = HibernateUtil.createEntityManager(); //I used JPA's EntityManager instead of hibernate's sessions. createEntityManager iss a function created by you.
EntityTransaction tx = em.getTransaction();
tx.begin();
Date startDate = new Date();
//... your DB stuff goes here ...
tx.commit();
Date endDate = new Date();
MyLogger.logTransactionDuration(startDate, endDate);
在上面的代码片段中,我让您了解如何实现这一目标。
如果需要,您可以使用log4j
或slf4j
api,并且只能在log4j.properties
文件中进行一些设置。
希望能提供帮助。