Skip to content

Commit c4fbad3

Browse files
author
Kim Barrett
committed
8351374: Improve comment about queue.remove timeout in CleanerImpl.run
Reviewed-by: rriggs, shade
1 parent ceac0eb commit c4fbad3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/java.base/share/classes/jdk/internal/ref/CleanerImpl.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -135,8 +135,14 @@ public void run() {
135135
mlThread.eraseThreadLocals();
136136
}
137137
try {
138-
// Wait for a Ref, with a timeout to avoid getting hung
139-
// due to a race with clear/clean
138+
// Wait for a Ref, with a timeout to avoid a potential hang.
139+
// The Cleaner may become unreachable and its cleanable run,
140+
// while there are registered cleanables for other objects.
141+
// If the application explicitly calls clean() on all remaining
142+
// Cleanables, there won't be any references enqueued to unblock
143+
// this. Using a timeout is simpler than unblocking this by
144+
// having cleaning of the last registered cleanable enqueue a
145+
// dummy reference.
140146
Cleanable ref = (Cleanable) queue.remove(60 * 1000L);
141147
if (ref != null) {
142148
ref.clean();

0 commit comments

Comments
 (0)