-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Getting Number of open connection from MYSQL using Hibernate
PostPosted: Wed Mar 15, 2006 3:29 pm 
Newbie

Joined: Wed Mar 15, 2006 3:13 pm
Posts: 3
I am using Jboss, Hibernate and MySQL. I want to know how many connections are opened after each business operation done. Can you please let me know the steps to follow for getting this done?

Thanks in advace,
Kalpesh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 8:21 pm 
Newbie

Joined: Tue Jun 07, 2005 10:45 pm
Posts: 15
Location: Sydney
Why would you want to know how many connections are sitting open and idle in a connection pool in JBoss?

Do you mean that you want to see the current connection usage level, as multiple requests are in-progress?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 10:28 am 
Newbie

Joined: Wed Mar 15, 2006 3:13 pm
Posts: 3
At some place, we have used JDBC and in some cases we used hibernate to access database. Now, after some business operations, we are running out of connections. So, I want to know after each business operation how many connections are opened to database collectively by direct JDBC call and hibernate. While getting connection from JDBC, we have used the same data source, we declared in hibernate configuration. So, I want to know whether hibernate provide such functionality. I tried the following code snippet but gives 0 all the time.

dBSession.getSessionFactory().getStatistics().getConnectCount()

Thanks,
Kalpesh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 5:44 pm 
Newbie

Joined: Tue Jun 07, 2005 10:45 pm
Posts: 15
Location: Sydney
We created a LoggedDataSource and LoggedConnection which manage a counter tracking the number of active connections.

The LoggedDataSource just delegates to a DataSource and wraps calls to getConnection with a LoggedConnection decorator.

DataSource.getConnection adds 1
Connection.close subtracts 1

We use Spring and just change our config when we want to look at max no. of concurrent connections during testing. This gives us an idea of the user to connection ratio needed.

The Counter object is configured in Spring also so its pretty easy to expose this as JMX if you want to watch it via a JMX console.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 2:37 pm 
Newbie

Joined: Wed Mar 15, 2006 3:13 pm
Posts: 3
So, there is no direct way to know the numbe of open connections with hibernate API? Is that what you mean?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 5:32 pm 
Newbie

Joined: Tue Jun 07, 2005 10:45 pm
Posts: 15
Location: Sydney
Don't know. I think you want to measure open connections at the datasource level, like I said.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.