8212132: (dc) Remove DatagramChannelImpl finalize method

Martin Buchholz martinrb at google.com
Wed Oct 23 20:38:46 UTC 2019


On Wed, Oct 23, 2019 at 12:59 PM Alan Bateman <Alan.Bateman at oracle.com>
wrote:

> On 23/10/2019 19:21, Martin Buchholz wrote:
>
> One possible safety idiom is to consistently have a static method
> returning a lambda (and don't pass in this!) , e.g.
>
> private static Runnable cleanerFor(FileDescriptor fd) { return () -> ...; }
>
> The cleaner is on the channel, the cleaning action is to close its file
> descriptor, so we need the reference to the channel.
>

You would call it like this:
this.cleanable = CleanerFactory.cleaner().register(this, cleanerFor(fd));
It's just moving code around, and only slightly safer/more disciplined.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20191023/25cbfe25/attachment.html>


More information about the nio-dev mailing list