< prev index next >

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

Print this page




 140                 !softCleanableList.isListEmpty()) {
 141             if (mlThread != null) {
 142                 // Clear the thread locals
 143                 mlThread.eraseThreadLocals();
 144             }
 145             try {
 146                 // Wait for a Ref, with a timeout to avoid getting hung
 147                 // due to a race with clear/clean
 148                 Cleanable ref = (Cleanable) queue.remove(60 * 1000L);
 149                 if (ref != null) {
 150                     ref.clean();
 151                 }
 152             } catch (Throwable e) {
 153                 // ignore exceptions from the cleanup action
 154                 // (including interruption of cleanup thread)
 155             }
 156         }
 157     }
 158 
 159     /**




















 160      * Perform cleaning on an unreachable PhantomReference.
 161      */
 162     public static final class PhantomCleanableRef extends PhantomCleanable<Object> {
 163         private final Runnable action;
 164 
 165         /**
 166          * Constructor for a phantom cleanable reference.
 167          * @param obj the object to monitor
 168          * @param cleaner the cleaner
 169          * @param action the action Runnable
 170          */
 171         public PhantomCleanableRef(Object obj, Cleaner cleaner, Runnable action) {
 172             super(obj, cleaner);
 173             this.action = action;
 174         }
 175 
 176         /**
 177          * Constructor used only for root of phantom cleanable list.
 178          */
 179         PhantomCleanableRef() {




 140                 !softCleanableList.isListEmpty()) {
 141             if (mlThread != null) {
 142                 // Clear the thread locals
 143                 mlThread.eraseThreadLocals();
 144             }
 145             try {
 146                 // Wait for a Ref, with a timeout to avoid getting hung
 147                 // due to a race with clear/clean
 148                 Cleanable ref = (Cleanable) queue.remove(60 * 1000L);
 149                 if (ref != null) {
 150                     ref.clean();
 151                 }
 152             } catch (Throwable e) {
 153                 // ignore exceptions from the cleanup action
 154                 // (including interruption of cleanup thread)
 155             }
 156         }
 157     }
 158 
 159     /**
 160      * Processes next Cleanable that has been waiting in the queue.
 161      *
 162      * @return {@code true} if a Cleanable was found in the queue and
 163      * was processed or {@code false} if the queue was empty.
 164      */
 165     public boolean cleanNextEnqueued() {
 166         Cleanable ref = (Cleanable) queue.poll();
 167         if (ref != null) {
 168             try {
 169                 ref.clean();
 170             } catch (Throwable t) {
 171                 // ignore exceptions from the cleanup action
 172             }
 173             return true;
 174         } else {
 175             return false;
 176         }
 177     }
 178 
 179     /**
 180      * Perform cleaning on an unreachable PhantomReference.
 181      */
 182     public static final class PhantomCleanableRef extends PhantomCleanable<Object> {
 183         private final Runnable action;
 184 
 185         /**
 186          * Constructor for a phantom cleanable reference.
 187          * @param obj the object to monitor
 188          * @param cleaner the cleaner
 189          * @param action the action Runnable
 190          */
 191         public PhantomCleanableRef(Object obj, Cleaner cleaner, Runnable action) {
 192             super(obj, cleaner);
 193             this.action = action;
 194         }
 195 
 196         /**
 197          * Constructor used only for root of phantom cleanable list.
 198          */
 199         PhantomCleanableRef() {


< prev index next >