Home arrow static arrow Java Programming [Archive] - close connection
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - close connection
1 Duke Stars available
This topic has 1 reply on 1 page.

Posts:10
Registered: 10/30/03
close connection  
Jul 6, 2004 1:09 AM



 
Hi all,

I need to close a connection when my object is garbage collected and I need to display message specifying the closed connection, I tried this by overridding the finalize() method but JVM is not calling the method when my object was collected, when I close the application I need to tell user the existing connection if any,. Any answer will be appreciated....

Thanks in advance
Srinivas....

 

Posts:342
Registered: 5/22/98
Re: close connection  
Jul 6, 2004 1:38 AM (reply 1 of 1)



 
Srinivas,

finalize is never guaranteed to be called. Do not write any code which must be done when an object is garbage collected. You will have to explicitly do any cleanup you need. As for closing on shutdown, you can add a shutdown hook using the Runtime class which will enable you to do some application level cleanup.

Graeme
 
This topic has 1 reply on 1 page.