Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Functions called in a finallize

Reply
Thread Tools

Functions called in a finallize

 
 
kikotores@yahoo.com
Guest
Posts: n/a
 
      08-07-2005
Im doing a program that connects to a database and I want to put
disconnect function in the finalize method in the class that does the
communication to the database. Is that a good idea ( seems like this
'destructor' does not work. Any good ideas how to do that?

 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      08-07-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Im doing a program that connects to a database and I want to put
> disconnect function in the finalize method in the class that does the
> communication to the database. Is that a good idea ( seems like this
> 'destructor' does not work. Any good ideas how to do that?


Finalisers are not destructors. They don't get called until sometime
after the garbage collector happens to find them. They are generally
useful for the implementation of resources that attempt to clean up even
if the client code is broken.

Instead use try/finally as:

Connection connection = getConnection();
try {
...
} finally {
connection.close();
}

Get a good book...

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie -- smart pointer destructor called without destructor everbeing called Jimmy Hartzell C++ 0 05-19-2008 07:05 PM
Why is a button Click event also called when a textbox TextChanged event is called??? S_K ASP .Net 6 11-08-2007 07:44 PM
What is called carry chain structure in FPGA is called in IC? Weng Tianxiang VHDL 6 09-12-2007 07:19 AM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM
three times copy ctor called, one ctor called, why? Apricot C++ 4 04-16-2004 07:55 AM



Advertisments