• Post Reply Bookmark Topic Watch Topic
  • New Topic

contextDestroyed and DataSource attribute question  RSS feed

 
nico dotti
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Sheriff
Posts: 37255
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nico,
This looks like it is more about the servlet lifecycle than JDBC. I'm going to move it to our servlets forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
nico dotti
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
nico dotti
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks for the input
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!