• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

contextDestroyed and DataSource attribute question

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks for the input
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic