About the finalization queue and reference queue

Jun Zhuang jun.zhuang at hobsons.com
Tue Oct 11 18:25:29 UTC 2016


Hi,

While reading about re-defining the finalize() method explicitly in a class I came across some statements and like to get some clarification from the experts.

On http://www.fasterj.com/articles/finalizer2.shtml, the author states that "the GC adds each of those Finalizer objects to the reference queue at java.lang.ref.Finalizer.ReferenceQueue.". Based on this the Finalizer object associated with the finalizeable object goes on the reference queue.

On page 311 of book Service-Oriented Computing - ICSOC 2011 Workshops<https://books.google.com/books?id=hIa5BQAAQBAJ&pg=PA311&lpg=PA311&dq=java,+finalization+queue&source=bl&ots=LLGiYGWh0L&sig=Glvf0kn0zKHrdWoPzM6y6wtsr_M&hl=en&sa=X&ved=0ahUKEwjHrsL2pdPPAhUk3IMKHdXRCtc4ChDoAQgbMAA#v=onepage&q=finalization%20queue&f=false> "... all those objects that have a finalize () method and are found to be unreachable(dead) by garbage collector, are pushed into a finalization queue.". So the finalizeable object goes on the finalization queue.

Then this site, https://yourkit.com/forum/viewtopic.php?f=3&t=4672, states that "Objects of all classes with redefined finalize() method are added to a queue at the moment of creation. The queue head is referenced from a static field in java.lang.ref.Finalizer. An instance of Finalizer is created for each "finalizeable" object and is stored in that queue, which is in fact a linked list of Finalizers.", so both the finalizeable object and the associated Finalizer object are stored in the same queue?

So my questions are: Are there one or two queues involved? Exactly how object finalization works?


Appreciate your input,
Jun

Jun Zhuang
Sr. Performance QA Engineer | Hobsons<https://www.hobsons.com/?utm_source=outlook&utm_medium=email&utm_campaign=banner_02.12.16_general>
T: +1 513 746 2288 | jun.zhuang at hobsons.com
50 E-Business Way, Suite 300 | Cincinnati, OH 45241 | USA


Upgraded by Hobsons - Subscribe Today
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-gc-use/attachments/20161011/afd226fa/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image755000.png
Type: image/png
Size: 13602 bytes
Desc: image755000.png
URL: <http://mail.openjdk.java.net/pipermail/hotspot-gc-use/attachments/20161011/afd226fa/image755000-0001.png>


More information about the hotspot-gc-use mailing list