aspose file tools
The moose likes Servlets and the fly likes contextDestroyed and DataSource attribute question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "contextDestroyed and DataSource attribute question" Watch "contextDestroyed and DataSource attribute question" New topic
Author

contextDestroyed and DataSource attribute question

nico dotti
Ranch Hand

Joined: Oct 09, 2007
Posts: 124
I'm using a DataSource to allow for pooling MySQL5 connection via Tomcat 6. I have a ServletContextListener and I'm wondering what the standard way of dealing with 'cleanup' is. Here's what I have as a first attempt. Suggestion? Thanks all:


[ January 24, 2008: Message edited by: nico dotti ]

[ January 24, 2008: Message edited by: nico dotti ]
[ January 24, 2008: Message edited by: nico dotti ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26158
    
  66

Nico,
This looks like it is more about the servlet lifecycle than JDBC. I'm going to move it to our servlets forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56167
    
  13

It looks to me like all that you are doing is a bunch of logging and removing application-scoped variables from the servlet context. This is wasted effort. The servlet context is about to go out of scope, and any scoped variables in application scope will go with it. it is completely unnecessary to remove them in a context listener.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
nico dotti
Ranch Hand

Joined: Oct 09, 2007
Posts: 124
So are you saying that the only things I need to close up are connections, statements, within my classes then right? What exactly does one use the contextDestroyed for then?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It's for cleaning up any resources that need to be cleaned up.
If you're using container managed connection pooling or opening and closing your connections within your servlets, then there probably won't be much if anything to clean up.

If, on the other hand, you've implemented your own connection pooling or if you are using something other than JDBC for persistance (legacy databases, etc) and have initialize something when the app starts and clean it up when it closes, this would be a good place to do it. Also some people spawn new threads from their applications to perform periodic tasks. This would be a good place for code that shuts down those threads gracefully.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
nico dotti
Ranch Hand

Joined: Oct 09, 2007
Posts: 124
Ok, thanks for the input
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: contextDestroyed and DataSource attribute question
 
Similar Threads
Netbeans & Tomcat Problem : Error messages included!
Enthuware weird question
Is TOMCAT'S JULI logging levels broken on Linux?
Anyone Use EClim (eclipse vim)
java.lang.NullPtrEx