You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Geeta Ramani <gr...@terralink.com> on 2004/07/26 15:52:56 UTC

Connecting to a database during sessionDestroyed(HttpSessionevent) in HttpSessionlistener class

This may be classified as OT, and if so, please ignore it or reply to me personally. Also if this question has already been answered I would appreciate it very much if anyone could send me a link: I can't come up with a good search criterion to google/search for.

I wrote a HttpSessionListener for our application and part of the sessionDestroyed(HttpSessionEvent)code involved getting a connection from our pool and deleting a ceratin record in a table in our database. When I tested this code locally this worked great but when I moved this to our server we noticed during testing that this code seemed to work inconsistently: It seemed to be executed sometimes and not at others. 

After worrying about it over the weekend, I think I figured out the problem: during testing we were all using the connection pool whose size we had deliberately set to 1 to see how slow things could get. Since the sessionDestroyed code involved getting a connection from the pool I think it must have timed out when all of us were testing the application. In which case, my code simply exited the try block doing nothing except log (which was mistakenly turned off for this class (:(.. Anyways, this explanation seems to explain everything we noticed.

One way to solve thsi problem is to not use the pool for this part of the app. That way it doesn't matter if there's an available connection or not, this code will always - well, as far as possible - be executed. (In the other parts of the app, if a connection cannot be obtained from the pool, at least the user is made aware of it. The HttpSessionListener of course doesn't have that luxury..)

But I kind of feel that this is not really a clean solution..? Can somebody comment on why I have a funny feeling about seeking this way out..? Anybody have any better ideas on how to solve this problem?

As always, many thanks in advance for any insights!
Geeta

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org