-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to best to detect opened and never closed sessions?
PostPosted: Wed Sep 19, 2007 7:11 pm 
Newbie

Joined: Wed Sep 19, 2007 1:54 pm
Posts: 5
Location: Houston TX
All,

Am attempting to detect cases where I have Hibernate session objects which have been opened and not closed. I wrote the following method:

public static String getOpenSessionsMsgString(Session sess) {
Statistics stats = sess.getSessionFactory().getStatistics();
long num_sessions = stats.getSessionOpenCount();
if (num_sessions > 0) {
return "Open sessions after close: " + num_sessions;
}
else {
return null;
}
}

which I am calling everywhere I do a close in the hopes of discovering when the "opened but not closed" sessions are being generated.

I call the above method and if the # of open sessions is > 0, I'll return a string which I'll print, like so:

ca.getSession().close();
sess_message = GeneralUtils.getOpenSessionsMsgString(ca.getSession());
if (sess_message != null) {
System.out.println("InvoiceService.queue: " + sess_message);
}

My questions are:

1) Should I expect to be able to get at the session open count through the session which I just closed?

2) Is there a way to look at the set of sessions that are managed by the session factory or can I just use this statistics object to look at the runtime state of the sessions.

Thanks,
Wes


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 7:17 pm 
Newbie

Joined: Wed Sep 19, 2007 1:54 pm
Posts: 5
Location: Houston TX
Apparently, from looking at my log file, my statistics are disabled. How do I enable them?

FYI, I am comfortable with Hibernate concepts (big ActiveRecord user in the Ruby world), but have not implemented anything with it.

Thanks,
Wes


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 1:11 pm 
Newbie

Joined: Wed Sep 19, 2007 1:54 pm
Posts: 5
Location: Houston TX
I know it's totally uncool to reply to your own post, but it feels like the correct thing to do to keep all of the info. together.

I got my statistics enabled, and I'm looking at this:

Statistics stats = sess.getSessionFactory().getStatistics();
long num_sessions_opened = stats.getSessionOpenCount();
long num_sessions_closed = stats.getSessionCloseCount();

long num_stranded_sessions = num_sessions_closed - num_sessions_opened;

Would num_stranded_sessions above be the correct value to look at for sessions which are causing the "unclosed connection - forgot to call close() on your session?" warnings?

Thanks,
WG


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.