RFR: 8287168: (fs) WatchService leaves thread running if not closed
Brian Burkhalter
bpb at openjdk.java.net
Thu Jun 2 14:56:34 UTC 2022
On Thu, 2 Jun 2022 14:08:28 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:
> The cleaners will never be invoked.
>
> `Poller` class is kept alive by a thread, and while the class is static, it holds a hard reference to the enclosing WatchService. See [Windows](https://github.com/openjdk/jdk/blob/8323d9a8e0fa99947bb2a34b6b76bfecb0861b67/src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java#L320) / [Linux](https://github.com/openjdk/jdk/blob/8323d9a8e0fa99947bb2a34b6b76bfecb0861b67/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java#L207)
>
> A test checking if `WeakReference`s to `WatchService`s are cleared during GC would probably catch that.
Indeed I did not see them invoked unless an explicit `System.gc()` call was made.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8986
More information about the nio-dev
mailing list