@@ -56,8 +56,8 @@ public class Cleaner {
5656 * 1. If a long-lived thread registers some objects in the beginning, but
5757 * then stops registering more objects, the previously registered
5858 * 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
6161 * objects.
6262 *
6363 * The Master Cleaner handles the first issue by regularly handling the
@@ -66,6 +66,9 @@ public class Cleaner {
6666 * instances with the Master's reference queue.
6767 */
6868
69+ public static final long MASTER_CLEANUP_INTERVAL_MS = 5000 ;
70+ public static final long MASTER_MAX_LINGER_MS = 30000 ;
71+
6972 private static class CleanerImpl {
7073 protected final ReferenceQueue <Object > referenceQueue = new ReferenceQueue <Object >();
7174 protected final Map <Long ,CleanerRef > cleanables = new ConcurrentHashMap <Long ,CleanerRef >();
@@ -118,10 +121,7 @@ protected synchronized boolean remove(long n) {
118121 }
119122 }
120123
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 {
125125 private static MasterCleaner INSTANCE ;
126126
127127 public static synchronized void add (Cleaner cleaner ) {
@@ -155,10 +155,10 @@ private MasterCleaner() {
155155 @ Override
156156 public void run () {
157157 long now ;
158- while ((now = System .currentTimeMillis ()) < lastNonEmpty + MAX_LINGER_MS || !deleteIfEmpty ()) {
158+ while ((now = System .currentTimeMillis ()) < lastNonEmpty + MASTER_MAX_LINGER_MS || !deleteIfEmpty ()) {
159159 if (!cleanerImpls .isEmpty ()) { lastNonEmpty = now ; }
160160 try {
161- Reference <?> ref = impl .referenceQueue .remove (CLEANUP_INTERVAL_MS );
161+ Reference <?> ref = impl .referenceQueue .remove (MASTER_CLEANUP_INTERVAL_MS );
162162 if (ref instanceof CleanerRef ) {
163163 ((CleanerRef ) ref ).clean ();
164164 } else {
0 commit comments