I'm using jboss 4.2 with Hibernate. i need to log transactions duration, so I have statistics on the average time it takes a transaction to complete or rollback. another issue I have is jboss JTA (arjuna) aborting long running transactions, so I need to know what timeout to configure there.
0
votes
1 Answers
0
votes
I think you should create a timer that will count the time between the transaction start and end. A possibility to achieve this can be:
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);
In the above snippet of code, I make you the idea of how you can achieve this.
If you want, you can use log4j
or slf4j
api, and you would to make only some settings in log4j.properties
file.
Hope to help.