On Mon, 8 Nov 2021 20:18:17 GMT, Roger Riggs <rri...@openjdk.org> wrote:
>> You have a point. >> >> BUT, at least it's a working example and not some pseudo code. We do want to >> move to working example code long term, don't we? >> >> When I see <cleaner>, I'm just wondering what those <> type operators are >> good for here... > > A cleaner can/should be shared within some scope and purpose, in this case > the example class . > Each cleaner has a dedicated Thread so its not a lightweight object and > should not be proliferated. > (Loom may be able to use Virtual Threads). > > The reasons to not share are a Cleaner are based on possible interference > between the cleanup callbacks. > If they share a thread and are non-trivial, it might slow other cleaners. If > the cleaner is created and shared > for a particular purpose it will share the thread resource and still be > efficient. The new example Cleaner instance _is_ shared, though on a pretty small scale (just among instances of CleaningExample). A demonstration of larger scale sharing of a Cleaner instance would be out of scope for this example. ------------- PR: https://git.openjdk.java.net/jdk/pull/6076