@@ -56,8 +56,8 @@ public class Cleaner {
56
56
* 1. If a long-lived thread registers some objects in the beginning, but
57
57
* then stops registering more objects, the previously registered
58
58
* objects will never be cleared.
59
- * 2. When a thread exists before all its registered objects have been
60
- * cleared, the ThreadLocal instance are lost, and so are the pending
59
+ * 2. When a thread exits before all its registered objects have been
60
+ * cleared, the ThreadLocal instance is lost, and so are the pending
61
61
* objects.
62
62
*
63
63
* The Master Cleaner handles the first issue by regularly handling the
@@ -66,6 +66,9 @@ public class Cleaner {
66
66
* instances with the Master's reference queue.
67
67
*/
68
68
69
+ public static final long MASTER_CLEANUP_INTERVAL_MS = 5000 ;
70
+ public static final long MASTER_MAX_LINGER_MS = 30000 ;
71
+
69
72
private static class CleanerImpl {
70
73
protected final ReferenceQueue <Object > referenceQueue = new ReferenceQueue <Object >();
71
74
protected final Map <Long ,CleanerRef > cleanables = new ConcurrentHashMap <Long ,CleanerRef >();
@@ -118,10 +121,7 @@ protected synchronized boolean remove(long n) {
118
121
}
119
122
}
120
123
121
- public static class MasterCleaner extends Cleaner {
122
- public static final long CLEANUP_INTERVAL_MS = 5000 ;
123
- public static final long MAX_LINGER_MS = 30000 ;
124
-
124
+ private static class MasterCleaner extends Cleaner {
125
125
private static MasterCleaner INSTANCE ;
126
126
127
127
public static synchronized void add (Cleaner cleaner ) {
@@ -155,10 +155,10 @@ private MasterCleaner() {
155
155
@ Override
156
156
public void run () {
157
157
long now ;
158
- while ((now = System .currentTimeMillis ()) < lastNonEmpty + MAX_LINGER_MS || !deleteIfEmpty ()) {
158
+ while ((now = System .currentTimeMillis ()) < lastNonEmpty + MASTER_MAX_LINGER_MS || !deleteIfEmpty ()) {
159
159
if (!cleanerImpls .isEmpty ()) { lastNonEmpty = now ; }
160
160
try {
161
- Reference <?> ref = impl .referenceQueue .remove (CLEANUP_INTERVAL_MS );
161
+ Reference <?> ref = impl .referenceQueue .remove (MASTER_CLEANUP_INTERVAL_MS );
162
162
if (ref instanceof CleanerRef ) {
163
163
((CleanerRef ) ref ).clean ();
164
164
} else {
0 commit comments