[concurrency-interest] Object finalization

Vitaly Davidovich vitalyd at gmail.com
Tue May 15 16:32:34 EDT 2012


I would say yes as we're all in agreement that finalization order is
unspecified, so if the fields themselves are of a type with a finalized
then they could already be finalized.

As for an exception in the constructor, looks like in JDK 6 and onwards the
finalizer will not run if an exception occurs before Object's constructor
exits (from Oracle's Secure Coding Guidelines for java, guideline 4-5).

Sent from my phone
On May 15, 2012 4:06 PM, "Dr Heinz M. Kabutz" <heinz at javaspecialists.eu>
wrote:

> Sure, the fields cannot be null, but would it be possible that they
> have already been finalized?
>
> On 15/05/2012, Bob Lee <crazybob at crazybob.org> wrote:
> > So there isn't any confusion, the original code is safe without null
> checks
> > in the finalizer. While the finalizer can run concurrently with other
> > methods, the JLS
> > guarantees<
> http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.6>that
> > the constructor will finish before the finalizer runs: "The completion
> > of an object's constructor happens-before (§17.4.5) the execution of its
> > finalize method (in the formal sense of happens-before)."
> >
> > Hans, I used your static volatile pinning trick in an experimental
> > ThreadLocal implementation I wrote. :-)
> >
> > See the "pin" field:
> >
> http://code.google.com/p/google-threadlocal/source/browse/trunk/main/java/lang/ThreadLocal.java
> >
> > Bob
> >
>
>
> --
> Dr Heinz M. Kabutz (PhD CompSci)
> Author of "The Java(tm) Specialists' Newsletter"
> Sun Java Champion
> IEEE Certified Software Development Professional
> http://www.javaspecialists.eu
> Tel: +30 69 75 595 262
> Skype: kabutz
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120515/a7a6ad95/attachment.html>


More information about the Concurrency-interest mailing list