tutorial on using Cleaner-based finalization

Rick Hillegas rick.hillegas at gmail.com
Thu May 4 23:28:22 UTC 2017

Thanks, Peter and Roger. In addition to the classes listed by Lance, a 
complete list of the affected finalizers can be found in this JIRA 


On 5/4/17 9:48 AM, Lance Andersen wrote:
>> On May 4, 2017, at 11:32 AM, Mandy Chung <mandy.chung at oracle.com> wrote:
>>> On May 3, 2017, at 11:16 PM, Peter Levart <peter.levart at gmail.com> wrote:
>>> Hi Rick,
>>> Allow me to join the discussion...
>>> On 05/04/2017 04:21 AM, Rick Hillegas wrote:
>>>> Thanks, Roger. That is a helpful example.
>>>> Derby is a component which can be quiesced and unloaded on resource-constrained platforms, then re-loaded when resources free up. Unloading means garbage collecting all the classloaders created by the component so that, at the end, not a single scrap of Derby code remains loaded. Has the Cleaner pattern been tested under these kinds of conditions? Can you point me at a Cleaner-based library which successfully unloads and reloads itself without leaking classloaders?
>>> Can you point me to a place in Derby code where you are currently using finalize() method for your purpose and I'll try to show you how to convert this to Cleaner API...
>>> I'm surprised that you actually need finalize() in Derby. Isn't this pure Java code? Usually finalize() is needed in situations where there's some non-Java resource which has to be cleaned-up when all the references to some Java object that represents it are gone. I'm curious what you need to clean in a pure Java library.
>> Please include me for the pointer to Derby code too.  This can be used serving as examples to migrate away from use of finalizers.  We also hope to do that in JDK to set up more examples.
> Here are a few examples I believe:
>   http://svn.apache.org/repos/asf/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientConnection.java <http://svn.apache.org/repos/asf/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientConnection.java>
> http://svn.apache.org/repos/asf/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java <http://svn.apache.org/repos/asf/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java>
> http://svn.apache.org/repos/asf/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java <http://svn.apache.org/repos/asf/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java>
>> Mandy
>   <http://oracle.com/us/design/oracle-email-sig-198324.gif>
>   <http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif>
>   <http://oracle.com/us/design/oracle-email-sig-198324.gif>Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
> Oracle Java Engineering
> 1 Network Drive
> Burlington, MA 01803
> Lance.Andersen at oracle.com <mailto:Lance.Andersen at oracle.com>

More information about the core-libs-dev mailing list