RFR: 8302899: Executors.newSingleThreadExecutor can use Cleaner to shutdown executor [v3]
Alan Bateman
alanb at openjdk.org
Wed Feb 22 16:17:14 UTC 2023
On Tue, 21 Feb 2023 19:38:08 GMT, Brent Christian <bchristi at openjdk.org> wrote:
>> Alan Bateman has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
>>
>> - Keep reference to Cleanable
>> - Merge
>> - Fix typo in comment, remove blank line
>> - Replace older test
>> - Initial commit
>
> src/java.base/share/classes/java/util/concurrent/Executors.java line 837:
>
>> 835: implements ScheduledExecutorService {
>> 836: private final ScheduledExecutorService e;
>> 837: DelegatedScheduledExecutorService(ScheduledExecutorService executor) {
>
> You might consider keeping a dedicated subclass ("CleanableDelegatedExecutorService"?). Such a class could save the Cleanable from Cleaner.register(), and override the shutdown() method to call Cleanable.clean(). This would reduce GC reference tracking, for instance in places where newSingleThreadExecutor() is used in a try-with-resources.
That might be better as that would clear the reference (so it won't be queued) when explicit shutdown (or closed). We do that in several places (as you know) at the cost of a reference to the Cleanable allowing "this" to escape during construction.
-------------
PR: https://git.openjdk.org/jdk/pull/12675
More information about the core-libs-dev
mailing list