• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Life of the JDBC-ODBC Connection object in a Thread??

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a Thread that runs every 10 seconds in which I establish a JDBC-ODBC connection in the run method. Now lets assume that I dont close it after I am done with it. If it's a totally java JDBC connection, then the Garbage Collector would take care of freeing the memory when the Thread gets called repeatedly and when the memory resources go low.

But if it's a JDBC-ODBC Connection, then what happens to the first instance of the connection object (the one created when the Thread was called for the first time) when the Thread gets called for the second time after 10 seconds. Please note that the variable name for the new connection is going to be the same. If the answer is that it's going stay in the heap, then for how long?

public void run()
{
try
{
Class.forName(DRIVER_NAME);
con = DriverManager.getConnection(DSN, USER, PWD);
stmt = con.createStatement();
..................
..................
}
catch (Exception e)
{}
}

Please help me out with this.

Thanks in advance!!
Raj
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you elaborate as to why you wouldn't close the connection? I think relying on the garbage collector would still cause a connection leak. The spec does not mandate JDBC drivers to cleanup in finalize. The recommended cleanup sequence would be:



I know this didn't answer your thread-specific question, but hopefully this will prevent future leakage.
 
Raj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats correct !!

But I am in the process of analysing an existing system which has a lot of loose ends in the code. I have to expose them and suggest a workaround.

Please help me out in this...
 
author & internet detective
Posts: 40913
840
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
"Raj",

We're pleased to have you here with us in the JDBC forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character.

Thanks,
Jeanne
Forum Bartender
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic