This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
In "Thinking in Java" chapter 4 question 11 and 12 are as follows:
11. Create a class with a finalize( ) method that prints a message. In main( ), create an object of your class. Explain the behavior of your program. Comment 12. Modify Exercise 11 so that your finalize( ) will always be called. Comment
I thought we can not be certain that finalize will be called. It is up to JVM even after System.gc call
Barb Hart
Greenhorn
Joined: Aug 06, 2002
Posts: 4
posted
0
I'm not sure if this is what the book meant... but you could call the finalize() method from a try/finally block. The finally should 'always' be executed, unless the thread is killed or system.exit happens first. Barbara Hart
protected void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. ... The finalize method is never invoked more than once by a Java virtual machine for any given object. ...
[ August 15, 2002: Message edited by: Valentin Crettaz ]
I'm pretty sure that not all of us have the F: drive mapped the same as yours. Anyway, using the finalize() method is generally not advisable, as it's execution is unpredictable. Paul [Link fixed by Val] [ August 15, 2002: Message edited by: Valentin Crettaz ]
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
Sorry guys, I fixed the link
Barb Hart
Greenhorn
Joined: Aug 06, 2002
Posts: 4
posted
0
I just came across this article in Java World on garbage collection and finalization. It explains system.gc() and system.runFinalization(). Although, as discussed in the other links and this article, even calling system.runFinalization() doesn't guarantee that it will run. http://www.javaworld.com/javaworld/jw-12-2001/jw-1207-java101-p3.html
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.